imagine what we have something like this:
<div id="xxx"><p>Hello World</p></div>
if we call .html function in this way:
$("#xxx").html();
we will get:
<p>Hello World</p>
But i need to get:
<div id="xxx"><p>Hello World</p></div>
So, what i need to do? I think to add another wrapper around #xxx, but this is not a good idea.
Just use standard DOM functionality:
$('#xxx')[0].outerHTML
Or a bit simpler with .prop()
:
$('#xxx').prop('outerHTML')
outerHTML
is well supported - verify at Mozilla or caniuse.
Create a temporary element, then clone()
and append()
:
$('<div>').append($('#xxx').clone()).html();
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