开发者

css() with appendTo() is not applicable

开发者 https://www.devze.com 2023-01-15 07:15 出处:网络
$(\'#item\').click(function(){ $.ajax({ url: \'server.php\', type: \'POST\', data : {temp :开发者_JAVA技巧 \'aValue\'},
 $('#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.

0

精彩评论

暂无评论...
验证码 换一张
取 消