Difference between clone() and clone(true)

Prabhukiran345
Posted by Prabhukiran345 under jQuery category on | Points: 40 | Views : 591
Clone( ) will not copy any event handlers attached to the cloned object. but clone(true) will copy event handlers attached too.

Example:Consider html code:
<b>Hello</b>
<p>, how are you?</p>


Now consider Script:
$('b').click(function () {
alert('Handler for .click() called.');
});

This indicates that if we click on Hello, then the alert have to be fired.

Now clone() Hello and add to paragraph:
$('b').clone().prependTo('p');


Now if we click on the Hello added to Paragraph,it will not show any Alert message.

Now use clone(true)
$('b').clone(true).prependTo('p');

This will fire alert message even in Hello added to Paragraph.

Comments or Responses

Login to post response