Repository navigation
DOM Manipulation
-
remove|empty|replaceWithClone -
append|prepend|before|after -
replaceWith|appendTo|prependTo -
insertBefore|insertAfter -
wrap|unwrap
Description Removes the set of matched elements from the DOM.
Parameters
- None.
Returns
- (jBase): The removed elements (detached).
Example
$('.ads').remove();Description Remove all child nodes of the set of matched elements from the DOM.
Parameters
- None.
Returns
- (jBase): Current instance.
Example
// Clears the content of .container but keeps the container itself
$('.container').empty();Description Replaces the selected elements with a deep clone of themselves. Useful for stripping event listeners.
Parameters
- None.
Returns
- (jBase): The new cloned elements.
Example
// Removes all events attached to the button by cloning it
$('button#reset').replaceWithClone();Description Insert content, specified by the parameter, to the end of each element in the set of matched elements.
Parameters
-
content(String|HTMLElement|jBase): The content to insert.
Returns
- (jBase): Current instance.
Example
$('.list').append('<li>New Item</li>');Description Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
Parameters
-
content(String|HTMLElement|jBase): The content to insert.
Returns
- (jBase): Current instance.
Example
$('.list').prepend('<li>First Item</li>');Description Insert content before each element in the set of matched elements.
Parameters
-
content(String|HTMLElement|jBase): The content to insert.
Returns
- (jBase): Current instance.
Example
$('#main').before('<div class="header"></div>');Description Insert content after each element in the set of matched elements.
Parameters
-
content(String|HTMLElement|jBase): The content to insert.
Returns
- (jBase): Current instance.
Example
$('#main').after('<div class="footer"></div>');Description Replace each element in the set of matched elements with the provided new content.
Parameters
-
content(String|HTMLElement|jBase): The content to insert.
Returns
- (jBase): Current instance (the old, detached elements).
Example
$('.old-element').replaceWith('<div class="new-element">Updated</div>');Description Insert every element in the set of matched elements to the end of the target.
Parameters
-
target(String|HTMLElement|jBase): The element to append to.
Returns
- (jBase): Current instance.
Example
$('<p>Test</p>').appendTo('.container');Description Insert every element in the set of matched elements to the beginning of the target.
Parameters
-
target(String|HTMLElement|jBase): The target element.
Returns
- (jBase): Current instance.
Example
$('<p>Intro</p>').prependTo('body');Description Insert every element in the set of matched elements immediately before the target element.
Parameters
-
target(String|HTMLElement): A CSS selector or DOM element before which the content will be inserted.
Returns
- (jBase): Current instance.
Example
$('<p>New Alert</p>').insertBefore('#main-content');Description Insert every element in the set of matched elements immediately after the target element.
Parameters
-
target(String|HTMLElement): A CSS selector or DOM element after which the content will be inserted.
Returns
- (jBase): Current instance.
Example
$('<span>* Required</span>').insertAfter('input.required');Description Wrap an HTML structure around each element in the set of matched elements.
Parameters
-
structure(String): HTML string specifying the structure (e.g.,<div class="wrapper"></div>).
Returns
- (jBase): Current instance.
Example
$('.item').wrap('<div class="item-wrapper"></div>');Description Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
Parameters
- None.
Returns
- (jBase): Current instance.
Example
// Removes the parent <div> but keeps the <span>
$('span').unwrap();