views:

29

answers:

2
 $('#item').click(function()  {

        $.ajax({
           url: 'server.php',
           type: 'POST',
           data : {temp : 'aValue'},
           success: function(data) {
           $(data).css('color', 'red').appendTo('#item');
         }    
       });
     });

The problem is here :

       $(data).css('color', 'red').appendTo('#item');

while it does takes the data and works well with the appendTo() the css part is not applicable

+1  A: 

Because data is a string, not an html element, thus why it's not css'd.

aularon
sorry, tap was open and it didn't say there's answers, so I answered.
aularon
hmm..can u help me how its gonna be an html element ? :/
t0s
Do as @strager suggested below, it works: http://jsfiddle.net/B3Wdr/
aularon
+1  A: 

Instead of

$(data).css('color', 'red').appendTo('#item');

try

$('<span/>').text(data).css('color', 'red').appendTo('#item');
strager