5.6 KiB
remove|empty|replaceWithCloneappend|prepend|before|afterreplaceWith|appendTo|prependToinsertBefore|insertAfterwrap|unwrap
.remove
Description Removes the set of matched elements from the DOM.
Parameters
- None.
Returns
- (jBase): The removed elements (detached).
Example
$('.ads').remove();
.empty
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();
.replaceWithClone
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();
.append
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>');
.prepend
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>');
.before
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>');
.after
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>');
.replaceWith
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>');
.appendTo
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');
.prependTo
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');
.insertBefore
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');
.insertAfter
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');
.wrap
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>');
.unwrap
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();