I'm having trouble with my code... I have a feeling its merely a careless error... but I cannot, for the life of me, find it. Here's my code:

            var now = new Date();
            var url = "out.jpg?" + now.getTime();
            im = $("<img>");
            im.hide();
            im.bind("load",function(){ $(this).fadeIn(); });
            $('#target').append(im);
            im.attr('src',url);             

This works fine; however I call this code in a loop, and it appends the image over and over and over... I tried using:

    $('#target').text(im);

But that had no effect... Help anyone?

有帮助吗?

解决方案

If the target is supposed to contain only this image, you can use html

 $('#target').html(im);

and that would replace the content with the image.

其他提示

You want to .empty() the div, before .append():

$('#target').empty().append(im);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top