Reputation: 59213
In a JQuery plugin I'm writing I want to hide all the contents of the <body>
tag by wrapping them in a div and calling .hide()
. What is the best way to wrap existing DOM elements into a single parent element?
For example:
I want to turn this
<body>
<h1>Hello World!</h1>
<p>This is a sample document to be manipulated by a JQuery plugin!</p>
</body>
into this
<body>
<div id="originalBodyContents">
<h1>Hello World!</h1>
<p>This is a sample document to be manipulated by a JQuery plugin!</p>
</div>
</body>
Thanks!
Upvotes: 3
Views: 7489
Reputation: 36672
This should do it...
$(document).ready(function() {
$('body').wrapInner('<div class="new" />');
$('.new').hide();
});
Here's a little fiddle to show something similar in action.
Upvotes: 11
Reputation: 8402
Any specific reason why you don't want to do the following?
$('body').hide();
Upvotes: 0