jquery method .not to remove nested div from string -
i need remove 1 of nested divs. can remove div#parent (+divs inside) with:
var $s = $(s).not('div#parent');
but can't remove 1 div inside (e.g. div#first):
var s = '<h1>heading</h1><div id="parent"><div id="first"><p>paragraph</p></div><div id="second"><p> second div</p></div></div>'; var $s = $(s).not('div#parent > div#first'); $('body').append($s); // shows html
how scenario done?
your .not
filtering top-level elements, $(s)
returns:
> $(s) [<h1>heading</h1>, <div id="parent">…</div>]
since both of them don't match selector, nothing removed set of matched elements.
find , remove elements instead:
var $s = $(s); $s.find('#first').remove();
Comments
Post a Comment