Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  39] [ 1]  / answers: 1 / hits: 112710  / 13 Years ago, thu, june 23, 2011, 12:00:00

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>
</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();
$('#save').val(x);


Check http://jsfiddle.net/rzfPP/58/


More From » jquery

 Answers
27

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 http://jsfiddle.net/rzfPP/68/



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



$('#container').unwrap();

[#91536] Wednesday, June 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyasiaalmap

Total Points: 294
Total Questions: 107
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
;