html | String | A string of HTML, that will be created on the fly and wrapped around the target. |
---|
Wrap all matched elements with a structure of other elements. This wrapping process is most useful for injecting additional stucture into a document, without ruining the original semantic qualities of a document.
This works by going through the first element provided (which is generated, on the fly, from the provided HTML) and finds the deepest ancestor element within its structure - it is that element that will en-wrap everything else.
This does not work with elements that contain text. Any necessary text must be added after the wrapping is done.
<p>Test Paragraph.</p>
$("p").wrap("<div class='wrap'></div>");
<div class='wrap'><p>Test Paragraph.</p></div>
elem | Element | A DOM element that will be wrapped around the target. |
---|
Wrap all matched elements with a structure of other elements. This wrapping process is most useful for injecting additional stucture into a document, without ruining the original semantic qualities of a document.
This works by going through the first element provided and finding the deepest ancestor element within its structure - it is that element that will en-wrap everything else.
This does not work with elements that contain text. Any necessary text must be added after the wrapping is done.
<p>Test Paragraph.</p><div id="content"></div>
$("p").wrap( document.getElementById('content') );
<div id="content"><p>Test Paragraph.</p></div>
content | Content to append to the target |
---|
Append content to the inside of every matched element.
This operation is similar to doing an appendChild to all the specified elements, adding them into the document.
Appends some HTML to all paragraphs.
<p>I would like to say: </p>
$("p").append("<b>Hello</b>");
<p>I would like to say: <b>Hello</b></p>
Appends an Element to all paragraphs.
<p>I would like to say: </p><b id="foo">Hello</b>
$("p").append( $("#foo")[0] );
<p>I would like to say: <b id="foo">Hello</b></p>
Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
<p>I would like to say: </p><b>Hello</b>
$("p").append( $("b") );
<p>I would like to say: <b>Hello</b></p>
content | Content to prepend to the target. |
---|
Prepend content to the inside of every matched element.
This operation is the best way to insert elements inside, at the beginning, of all matched elements.
Prepends some HTML to all paragraphs.
<p>I would like to say: </p>
$("p").prepend("<b>Hello</b>");
<p><b>Hello</b>I would like to say: </p>
Prepends an Element to all paragraphs.
<p>I would like to say: </p><b id="foo">Hello</b>
$("p").prepend( $("#foo")[0] );
<p><b id="foo">Hello</b>I would like to say: </p>
Prepends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.
<p>I would like to say: </p><b>Hello</b>
$("p").prepend( $("b") );
<p><b>Hello</b>I would like to say: </p>
content | Content to insert before each target. |
---|
Insert content before each of the matched elements.
Inserts some HTML before all paragraphs.
<p>I would like to say: </p>
$("p").before("<b>Hello</b>");
<b>Hello</b><p>I would like to say: </p>
Inserts an Element before all paragraphs.
<p>I would like to say: </p><b id="foo">Hello</b>
$("p").before( $("#foo")[0] );
<b id="foo">Hello</b><p>I would like to say: </p>
Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.
<p>I would like to say: </p><b>Hello</b>
$("p").before( $("b") );
<b>Hello</b><p>I would like to say: </p>
content | Content to insert after each target. |
---|
Insert content after each of the matched elements.
Inserts some HTML after all paragraphs.
<p>I would like to say: </p>
$("p").after("<b>Hello</b>");
<p>I would like to say: </p><b>Hello</b>
Inserts an Element after all paragraphs.
<b id="foo">Hello</b><p>I would like to say: </p>
$("p").after( $("#foo")[0] );
<p>I would like to say: </p><b id="foo">Hello</b>
Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
<b>Hello</b><p>I would like to say: </p>
$("p").after( $("b") );
<p>I would like to say: </p><b>Hello</b>
deep | Boolean | (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself. |
---|
Clone matched DOM Elements and select the clones.
This is useful for moving copies of the elements to another location in the DOM.
Clones all b elements (and selects the clones) and prepends them to all paragraphs.
<b>Hello</b><p>, how are you?</p>
$("b").clone().prependTo("p");
<b>Hello</b><p><b>Hello</b>, how are you?</p>
content | Content to append to the selected element to. |
---|
Append all of the matched elements to another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).append(B), in that instead of appending B to A, you're appending A to B.
Appends all paragraphs to the element with the ID "foo"
<p>I would like to say: </p><div id="foo"></div>
$("p").appendTo("#foo");
<div id="foo"><p>I would like to say: </p></div>
content | Content to prepend to the selected element to. |
---|
Prepend all of the matched elements to another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).prepend(B), in that instead of prepending B to A, you're prepending A to B.
Prepends all paragraphs to the element with the ID "foo"
<p>I would like to say: </p><div id="foo"><b>Hello</b></div>
$("p").prependTo("#foo");
<div id="foo"><p>I would like to say: </p><b>Hello</b></div>
content | Content to insert the selected element before. |
---|
Insert all of the matched elements before another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).before(B), in that instead of inserting B before A, you're inserting A before B.
Same as $("#foo").before("p")
<div id="foo">Hello</div><p>I would like to say: </p>
$("p").insertBefore("#foo");
<p>I would like to say: </p><div id="foo">Hello</div>
content | Content to insert the selected element after. |
---|
Insert all of the matched elements after another, specified, set of elements. This operation is, essentially, the reverse of doing a regular $(A).after(B), in that instead of inserting B after A, you're inserting A after B.
Same as $("#foo").after("p")
<p>I would like to say: </p><div id="foo">Hello</div>
$("p").insertAfter("#foo");
<div id="foo">Hello</div><p>I would like to say: </p>
expr | String | (optional) A jQuery expression to filter elements by. |
---|
Removes all matched elements from the DOM. This does NOT remove them from the jQuery object, allowing you to use the matched elements further.
Can be filtered with an optional expressions.
<p>Hello</p> how are <p>you?</p>
$("p").remove();
how are
<p class="hello">Hello</p> how are <p>you?</p>
$("p").remove(".hello");
how are <p>you?</p>
Removes all child nodes from the set of matched elements.
<p>Hello, <span>Person</span> <a href="#">and person</a></p>
$("p").empty()
[ <p></p> ]