开发者

appendTo not working for this function yet append works

Ok, So I have over 1000 lines of jQuery code, and other functions are also using appendTo and it works.

However it seems that the following function appendTo wont work, while append does work.

I think it is because I am creating the DIV in the jquery file and the asking another function to fill that div. but am not sure if that is the reason.

here is the function that is playing up.

function getmessage(e) {
    $('#loadmessage').html("");
    $.getJSON('sys/classes/usermessage.php?task=fetch&subkey=' + 开发者_JAVA百科e + '&userid=' + sessionparts[1], function(getmessage) {
        // get line status
        $.each(getmessage, function(i, item) {

            $('#loadmessage').append(item.subkey);
        });
    });    
};


The reason is that .appendTo() will not work in this case because your item.subkey is not a dom element. You have 2 choices.

1) Use .append() as your code is now

2) For using .appendTo() put your item.subkey in a dom node, as the following:

$.each(getmessage, function(i, item) {
    $("<span />").text(item.subkey).appendTo('#loadmessage');
});

Hope this helps. Cheers

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜