Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery append closing div tag only

Tags:

html

jquery

css

I am building a "universal wrapper" for several different external sites that would build a nav and footer with jquery and xml.

My problem: Since the script will be used on multiple sites that were built by other people, I need to build a container out just inside the opening and closing body tags. I have been able to target the body to prepend <div id="wrapper">, but I need to close the div somehow and trying to append only </div> does not work.

This is what I'm trying to do:

$(document).ready(function(){
    $("body").append("</div>");
});

My question: Is there a way to render </div> on its own?

like image 728
deadbinky Avatar asked Feb 26 '26 19:02

deadbinky


1 Answers

Have you looked at .wrapInner()? It will allow you to wrap all of the contents of <body></body> with a starting and ending tag:

$("body").wrapInner("<div id='wrapper'></div>");

That will result in:

<body>
  <div id="wrapper">
    <!-- original markup here -->
  </div>
</body>

Caution: One thing I noticed was the fact that jQuery will create the wrapper twice if the script is ran from within the body tags.

like image 69
Sampson Avatar answered Mar 01 '26 10:03

Sampson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!