clone() method

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("body").append($("p").clone());
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Copy each p element, then append to the body element</button>
</body>
</html>

 

Clone and append a p element:

Definition and Usage

The clone() method makes a copy of the selected element, including child nodes, text, and attributes.

grammar

$(selector).clone(includeEvents)
parameter describe
includeEvents

Optional. Boolean value. Specifies whether to copy all event handling for the element.

By default, event handlers are not included in replicas.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326071024&siteId=291194637