JavaScript Tutorial/jQuery/clone
Содержание
Add cloned tag
<source lang="javascript">
<html>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").clone().add("Again").appendTo(document.body);
});
</script>
<style>
div { width:40px; height:40px; margin:10px; float:left;}
</style>
</head>
<body>
<body>
Hello
</body>
</html></source>
Clone matched DOM Elements
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("b").clone().prependTo("p");
}); </script>
</head> <body> <body>Hello
, how are you?
</body>
</html></source>
Clone paragraph tag
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").clone().appendTo(document.body); }); </script> <style> div { width:40px; height:40px; margin:10px; float:left;} </style> </head> <body> <body>
Hello
</body>
</html></source>
clone(true): moving copies of the elements, and their events, to another location in the DOM.
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("b").clone(true).prependTo("p"); }); </script> </head> <body> <body>Hello
, how are you?
</body>
</html></source>
clone(): useful for moving copies of the elements to another location
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("b").clone().prependTo("p"); }); </script> </head> <body> <body>Hello
, how are you?
</body>
</html></source>