doom
October 26, 2022, 1:42pm
1
Hello, I am new to jQuery. I want to copy a div into another div. I am trying to create a popup where I want to copy selected content. I have the following HTML.
<div class="content">
<h1>Title</h1>
<p>Some Content</p>
</div>
Now I want to copy the content to the div below.
<div class="popup">
<!-- Copy the content here -->
</div>
nazmun
October 26, 2022, 1:51pm
2
You can use jQuery clone()
method or html()
method to get a copy of the element.
var elem = $('.content').clone();
$('.popup').html(elem);
Or
var elem = $('.content').html();
$('.popup').html(elem);
Note, if html()
method is empty then it will get an element but if you pass some data then it will set the HTML value