jQuery remove but not container DIV -
i have function:
$('#addnote').click(function() { var html = '<div class="row-fluid" id="notenote"><div class="span9">' + $('#notecontent').val() + '<input type="hidden" value="' + $('#notecontent').val() + '" name=notes[]>' + '</div>' + '<div class="span3 ">' + '<img width="68" height="60" src="getimage.php?image=current_admin">' + '<div class="pull-right">' + ' ' + '<a href="javascript:void(0)" class="removenote"><i class="icon-remove"></i></a>' + ' ' + '</div>' + '</div>' + '</div>'; if ($('#notecontent').val() !== '') { $('#notecontent').val(''); var newnote = $("#notecontainer").append(html); newnote.find('.removenote').on("click", function(event) { event.preventdefault(); newnote.remove(); }); } });
the problem when newnote.remove()
fired, deletes main container div #notecontainer
while should remove itself, div #notenote
, nothing else. how can fix code?
thanks
replace code:
newnote.remove();
with this:
$(this).closest('#notenote').remove();
Comments
Post a Comment