I don't need innerHTML i need innerHTML with enclosing tags. Lets write some example:
<div id="1" style="qwe"><span class="1"></span></div>
<div id="2" style="asd"><span class="2"></span></div>
<div id="3" style="zxc"><span class="3"></span></div>
I can get element by id:
$("#1")
And how can i get string like that:
<div id="1" style="qwe"><span class="1"></span></div>
Of course html() doesn't work becouse it will return only span.
you could do something like this:
alert( $('#\\31 ').wrap("<div />").parent().html() )
$('#\\31 ').unwrap()
Something like this should work fine:
jQuery.fn.outerHTML = function(s) {
return s
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
};
var outer = $("#1").outerHTML();
Here's a working fiddle.
Additional Info
See http://www.yelotofu.com/2008/08/jquery-outerhtml/ for original article .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With