2

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>'); 
return 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?

1 Answer 1

4

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>');
});
1
  • Thanks, I am just starting out with jQuery, this was a huge help.
    – OwlBoy
    Feb 27, 2010 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.