Copy the first p element including event handlers, and append to body element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:clone

Description

Copy the first p element including event handlers, and append to body element

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("body").append($("p:first").clone(true));
    });/*from ww  w . ja va  2  s .c  o  m*/
    $("p").click(function(){
        $(this).animate({fontSize: "+=1px"});
    });
});
</script>
</head>
<body>

<p>Click this paragraph to increase text size.</p>
<p>This is another paragraph.</p>

<button>Test</button>

</body>
</html>

Related Tutorials