jquery clone() method


  Translation results:

clone

UK[kləʊn] US[kloʊn]

n. (of animals and plants) cloning; asexual reproduction line; replicating people (or animals and plants) ; (not thinking) a person who acts mechanically, a robot

vt.& vi. copy; clone, (make something) reproduce asexually; cultivate... into pure cells

jquery clone() methodsyntax

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

Syntax: $(selector).clone(includeEvents)

Parameters:

ParametersDescription
includeEvents Optional. Boolean value. Specifies whether all event handling of the element is copied. By default, event handlers are not included in the replica.

jquery clone() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.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>复制每个 p 元素,然后追加到 body 元素</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A