Are events also copied when you clone an element in jQuery?
Are events also copied when you clone an element in jQuery?
Using clone()
method, we can create clone of any element but the default implementation of the clone()
method doesn’t copy events unless you tell the clone()
method to copy the events. The clone()
method takes a parameter, if you pass true then it will copy the events as well.
1 |
$(document).ready( function (){ |
2 |
$( "#btnClone" ).bind( 'click' , function (){ |
3 |
$( '#dvClickme' ).clone( true ).appendTo( 'body' ); |
4 |
}); |