« Back to the full jQuery 1.2 Release Notes.
.wrapInner() is designed to wrap the inner child contents of each matched element (including text nodes).
$("p").wrapInner("<b></b>");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("p").wrapInner("<b></b>");
});
</script>
</head>
<body>
<p>Hello</p><p>cruel</p><p>World</p>
</body>
</html>
.wrapAll() will wrap all the elements in the matched set into a single wrapper element (this is different from .wrap() where each element in the matched set would get wrapped with an element).
$("p").wrapAll("<div></div>");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("p").wrapAll("<div></div>");
});
</script>
<style>div{ border: 2px solid black; }</style>
</head>
<body>
<p>Hello</p><p>cruel</p><p>World</p>
</body>
</html>
replaceWith replaces all matched elements with the specified HTML or DOM elements.
$("p").replaceWith("<b>Paragraph. </b>");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("p").replaceWith("<b>Paragraph. </b>");
});
</script>
</head>
<body>
<p>Hello</p><p>cruel</p><p>World</p>
</body>
</html>
replaceAll replaces the elements matched by the specified selector with the matched elements.
$("<b>Paragraph. </b>").replaceAll("p");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("<b>Paragraph. </b>").replaceAll("p");
});
</script>
</head>
<body>
<p>Hello</p><p>cruel</p><p>World</p>
</body>
</html>
The clone method can now take an optional argument where, if true, it will also clone all the event handlers on all the cloned elements.
$("button").click(function(){
$(this).clone(true).insertAfter(this);
});
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(this).clone(true).insertAfter(this);
});
});
</script>
</head>
<body>
<button>Clone Me!</button>
</body>
</html>