Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Clone an element without the children in jQuery

I have a table and I want to clone it without its children. Note that I simplified the markup for brevity, the table has many properties and event handlers which I also want to copy.

<table data-x="..." class="a b c">

I don't want to copy all then delete the children afterwards, I'm not sure but I think it's not efficient.

like image 781
dpp Avatar asked Mar 16 '23 01:03


1 Answers

I don't think you can clone just the element without it's children using jQuery but you can do that with plain JavaScript. node.cloneNode(). This won't copy attached event listeners


like image 134
Vigneswaran Marimuthu Avatar answered Mar 24 '23 11:03

Vigneswaran Marimuthu