Categories: jQuery

jQuery clone – create a deep copy of matched elements

Share

The jQuery clone() Method creates a deep run time copy of set of matched DOM Elements  to another location in the DOM elements and select the clones.

This is very useful for run time copies of the elements to another location in the DOM elements.

Syntax:

$(selector).clone(true|false)

true: specifies the event handlers which should be copied
false: default. specifies the event handlers should not be copied

Read jQuery reference for more details.

Example of jQuery clone():

<p>This is a first paragraph.</p>
<p>This is a second paragraph.</p>
<script>
$(document).ready(function(){
$("p").clone().appendTo("body");
});
</script>

In the above example, it clone all <p> elements and then insert them at the end of the <body> element.

Must Read: Add table row dynamically in jQuery

Recent Posts

Recover From Google Penalties in 10 Steps in 2024

Facing Google penalties can be a daunting challenge for businesses relying on organic search traffic.…

10 hours ago

What is the Future of Artificial Intelligence?

Technology, undeniably, has made our lives easier. But the advent of artificial intelligence has been…

13 hours ago

Role of guest post services in SEO

Guest post services have become an essential tool for businesses and individuals looking to increase…

21 hours ago

Top Programming Trends You Need to Know in 2024

Programming continues to evolve at a rapid pace, with new trends and technologies emerging every…

1 day ago

Why startups need a digital marketing strategy?

Let’s be honest; a startup business hardly has sufficient amount to promote their services and…

2 days ago

How to Find the Best SEO Consultant in Toronto to Boost Your Rankings

Introduction In today's digital age, having a strong online presence is crucial for businesses in…

2 days ago