How to hide all elements except one using jquery?

Viewed 86130

I have HTML page:

<head></head>
<body>
  <div>
    <div>
      <div id="myDiv">
      </div>
    </div>
  </div>
</body>

How to hide all divs, and just have the myDiv inside the body using jquery?

Update

The page may contain some other html elements such as some tables, anchors, p, and i just want to see the myDiv element.

4 Answers

If you're objective is just to see that content and not see anything else, you can always just do this. You don't need jQuery:

document.body.innerHTML=document.getElementById('myDiv').innerHTML;
Related