开发者

Prepending unclosed tags in jQuery

Due to some limitations on the place files are being placed, I would like to prepend and append page structure just after the opening body tag and just before the closing body tag.

<script type="text/javascript">
$(document).ready(function() {
$('body').prepend('<div id="header"><div id="title"></div></div><div id="wrapper"><div id="content">'); 
$('body').append('</div></div><div id="footer"></div>'); 
r开发者_C百科eturn false;  
});
</script>

My code does this, but it also closes all open div tags when using prepend. And append removes all tags that appear to be closing nothing.

Is this just a poor way to do what I am trying to do? Can I tell jQuery to stop "fixing" my html for me? Is the browser what is fixing my tags and not jQuery?


Use .wrapInner() for this:

$(function() {
  $('body').wrapInner('<div id="wrapper"><div id="content"></div></div>');
  $('body').prepend('<div id="header"><div id="title"></div></div>'); 
  $('body').append('<div id="footer"></div>');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜