mt0s
mt0s

Reputation: 5811

css() with appendTo() is not applicable

 $('#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

Upvotes: 0

Views: 838

Answers (2)

strager
strager

Reputation: 90062

Instead of

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

try

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

Upvotes: 1

aularon
aularon

Reputation: 11110

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

Upvotes: 1

Related Questions