Keep only a subtree of the DOM tree

Posted by Randomblue on Stack Overflow See other posts from Stack Overflow or by Randomblue
Published on 2011-11-13T17:22:12Z Indexed on 2011/11/13 17:51 UTC
Read the original article Hit count: 430

Filed under:
|

On BBC articles, such as this one, there is a DOM element with class story-body, deep in the DOM chain.

I want to hide all DOM element "outside" of this (unique) DOM element. The problem is that I can't just do

$('*').hide();
$('.story-body');

because I need to make sure to keep the parents, grand-parents, etc. of story-body. I also can't do

$('*').hide();

var current = $('.story-body').show();
while(current = current.parent()) {
   current.show();
}

because that would simply show everything.

Any suggestions?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about dom