Home >Web Front-end >JS Tutorial >Detailed explanation of usage examples of clone() function in jQuery
This article mainly introduces the usage of clone() method in jQuery. It analyzes the function and definition of clone() method and the usage skills of cloning matching DOM elements with examples. Friends in need can refer to the following
The example in this article describes the usage of clone() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method clones matching DOM elements and selects these cloned copies and all their event handling.
Grammar structure:
The code is as follows:
$(selector).clone(Events, deepEvents)
Parameter list:
Example code:
The code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>脚本之家</title> <style type="text/css"> p{ width:200px; height:200px; border:1px solid blue; } p{ width:200px; height:200px; border:1px solid green; } </style> <script type="text/ javascript " src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $( document ).ready(function(){ $("button").click(function(){ $("p").clone().insertBefore("p"); }) }) </script> </head> <body> <p>我是p</p> <p>我会被克隆</p> <button>点击查看效果</button> </body> </html>
The above is the detailed content of Detailed explanation of usage examples of clone() function in jQuery. For more information, please follow other related articles on the PHP Chinese website!