Reputation: 12512
I need to select HTML block but exclude one div with specific class.
<div id="myHTML">
<p>...</p>
<div>...</p>
... more HTML here
<div id="exludeMe">
...
</div>
</div>
So I'm trying to use .not() but with no luck...
$("#myHTML").not('#exludeMe').html();
What am I missing? Is it because it's withing selected block of HTML? How do I bump it out?
Upvotes: 1
Views: 210
Reputation: 36784
not()
excludes elements from the initial selection, not descendants of those in the selection.
You should make a clone if you don't want to alter the original, you can then go on to find the elements you desire, remove them, and get the HTML of the previous element set (#myHTML
):
var html = $("#myHTML").clone().find('#exludeMe').remove().end().html();
Upvotes: 3