css() with appendTo() is not applicable
$('#item').click(function() {
$.ajax({
url: 'server.php',
type: 'POST',
data : {temp :开发者_JAVA技巧 '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
Instead of
$(data).css('color', 'red').appendTo('#item');
try
$('<span/>').text(data).css('color', 'red').appendTo('#item');
Because data is a string, not an html element, thus why it's not css'd.
精彩评论