Reputation: 11746
All my div blocks use the same class name and I need to append a new div block after a file upload has completed. The way I'm doing it now appends a new block to every existing block. Here is my test code:
HTML:
<div class="img_container" id="img1">EXISTING BLOCK</div>'
<div class="img_container" id="img2">EXISTING BLOCK</div>'
JQuery:
$('#fileupload').bind('fileuploadcompleted', function (e, data) {
e.preventDefault();
var $newdiv = $('<div class="img_container" id="img3">NEW BLOCK</div>');
$('.img_container').append($newdiv);
})
I've also tried appending to the body tag but the new div never appears. Any idea how I can solve this?
Upvotes: 0
Views: 182
Reputation: 9622
$('.img_container:last').after($newdiv) // should do the trick
Upvotes: 5