jquery - Append to body then remove - can't get it to remove -
i've simple modal window appends body - clicking close button should remove thought no. i've tried $(this).remove(); , took out button not appended text - have gone wrong?
$(function(){ var qrcodediv='<div id="qrblock"><a href="#" class="closeqr">x</a></div>' $(".add").click(function(){ $('body').append(qrcodediv); }); $('a.closeqr').live("click", function() { $('body').remove(qrcodediv); }); });
.remove()
not accept arbitrary html string. such syntax useful creating elements, that's not .remove()
does.
change $('body').remove('#qrblock')
or $('#qrblock').remove()
.
note code in question insert multiple elements same id when click
callback runs more once, which big no-no , lead undefined behavior.
Comments
Post a Comment