Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery .html() usage

Say I have

<div id="controller">
 <div id="first">1</div>
 <div id="second">2</div>
</div>

$('#controller').html().which returns

<div id="first">1</div>
<div id="second">2</div>

How do I get .html() to return

<div id="controller">
 <div id="first">1</div>
 <div id="second">2</div>
</div>

Or is there an alternate function for that?

like image 818
ade19 Avatar asked Jan 25 '26 08:01

ade19


1 Answers

Wrap it (ie. a clone) inside another parent

$('<div></div>').append($('#controller').clone()).html();

Also, check out a similar question.

like image 100
Yanick Rochon Avatar answered Jan 27 '26 20:01

Yanick Rochon



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!