This example is from a book.
It tells me that I can clone the paragraph without text if I set the parameter in the clone() to be false.
I checked out the documentation in the jQuery and I tried out all the combination of true and false.
The results proved that I cannot copy the paragraph without text.
Is it just a bug in jQuery?
<html>
<head>
<title>Copying element</title>
<script src="../jquery-1.8.0.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//copy elment and insert
$('div.chapter p:eq(0)').clone(false).insertBefore('div.chapter');
});
</script>
<style type="text/css">
span.footnote{
font-style:italic;
display:block;
}
.chapter span.footnote{
display:inline;
}
.chapter p{
width:50%;
}
</style>
</head>
<body>
<h1 id="f-title">Flatland: A ROmance of Many Dimension</h1>
<div id="f-author">by Edwin A. Abbott</div>
<h2>Part 1, Section 3</h2>
<h3 id="f-subtitle">Concerning the Inhabitants of Flatland</h3>
<div id="excerpt">an excerpt</div>
<div class="chapter">
<p class="squre">Our professional Men and Gentlemen are Squares (to which class I myself belong) and FIve-Sided Figures
or Pentagons.
</p>
<p class="mobility hexagon">Next above these come the Nobility of whoem there are serverl degress
<a href="http://en.wikipedia.org/wiki/Hexagon">Hexagons</a>and from thence rising in the number of theirside till they received the honourable title of
<a href="http://en.wikipedia.org/wiki/Polygon">Polygonal</a>
</p>
<p><span class="pull-quote">It is a <span class="drop">Law of Nature</span>with us that a mable child shall have </span>
</p>
<p>But this rule applies not always to the Tradesman</p>
<p>Rarely -- in proportion to the vast numbers of Isosceles
</p>
<p>The birth of tha Ture Equlaterial Traignel from Isoscele parents is the subject of rejociing in the coutry for many furlongs.
</p>
<p>How admirable is the Law of Compensation!
</p>
</div>
</body>
</html>
Re-read the clone documentation.
It specifies the element is copied WITH its content (deep copy). The boolean parameters only deals with event handlers and jquery data, not embedded elements.
So this is the normal comportment : the first paragraph in div.chapter (
$('div.chapter p:eq(0)')) is copied with its content.If you want a non-deep cloning function you could use this one :
but I’m not sure there is a real use for this.