I’m trying to remove everything in the whole body, except of a single element and its children. How can I accomplish this?
Edit 1
Consider the following markup:
<html>
<body>
<div id="div1"></div>
<div id="div2">
<div id="elementNotToRemove"></div>
</div>
<div id="div3"></div>
<div id="div4"></div>
</body>
</html>
In the above example, I want to remove div1, div3 and div4, as well as their children, but conserve div2 because it contains the element not to remove.
You can replace the not() part with whatever you want to keep