Pinkie Pinkie - 4 months ago 24x
jQuery Question

jQuery get html of container including the container itself

How do i get the html on '#container' including '#container' and not just what's inside it.

<div id="container">
<div id="one">test 1 </div>
<div id="two">test 2 </div>
<div id="three">test 3 </div>
<div id="four">test 4 </div>

I have this which gets the html inside #container. it does not include the #container element itself. That's what i'm looking to do

var x = $('#container').html();



If you wrap the container in a dummy P tag you will get the container HTML also.

All you need to do is

var x = $('#container').wrap('<p/>').parent().html();

Check working example at

To unwrap()the <p> tag when done, you can add