开发者

how to embed the whole <body> to a created new div with jQuery?

I want to perform the sticky footer to a stand-for-a-long web project. I'm required to create two top-level div and wrap up all the content inside of <body> into 'div-container', 开发者_JS百科then to add 'div-footer' to the end of <body> or <html> like

<body>
<div id='container'>
//all body 
</div>
<div id='footer'>
</div>
</body>

How can i do it with jQuery? i tried but failed with the code below (coz 'container' don't know where to append),

$(document).ready(function() {
    addStikyFooter();
});

function addStikyFooter() {
    $("<div id='container'></div>").append($('body'));
    var footerHtml = "<div id='footer'>i'm testing!/footer>";
    alert($('body').html());
}


Use append:

    $("body").append("<div id='footer'></div>");

Append will add your code at the end, but within the specified element. So $("body").append() will add things within the body.

In your code it looks like you switched the order of the content and the element to append to, so your code should read:

$(document).ready(function() {
    addStikyFooter();
});

function addStikyFooter() {
    $("body").append("<div id='container'></div>");
    $("body").append("<div id='footer'>i'm testing!</div>");
}

Updated example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜