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>');
});
精彩评论