简体   繁体   中英

How can I wrap the entire page contents in a div using jquery

Here is my code.

$(function(){
    $("body").prepend('<div id="loading"><span id="pagename"></span></div><div id="fade_wrapper">');
    $("body").append('</div> <!-- closing #fade_wrapper -->');
});

The problem is that chrome auto closes the open <div id="fade_wrapper"> so that the HTML looks like this:

<div id="loading"><span id="pagename"></span></div><div id="fade_wrapper"></div>

That closing DIV in the second code shouldn't be there. How can I wrap the entire page contents in a div using jquery?

Use .wrapInner :

$("body").wrapInner('<div id="loading"...');

append and prepend don't work that way. You prepend/append nodes , not tags .

It seems like you want to prepend some separate HTML as well. No matter:

$("body").wrapInner('<div id="fade_wrapper">');
$("body").prepend('<div id="loading"><span id="pagename"></span></div>');

The .prepend is done second so that it will be outside of the wrapping.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM