From d53aed4525a51c68815df9af018e74f3c11b7e54 Mon Sep 17 00:00:00 2001 From: Sven Minio Date: Sun, 17 May 2026 19:54:03 +0200 Subject: [PATCH] Add DOM Manipulation --- DOM-Manipulation.md | 312 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 DOM-Manipulation.md diff --git a/DOM-Manipulation.md b/DOM-Manipulation.md new file mode 100644 index 0000000..1be590c --- /dev/null +++ b/DOM-Manipulation.md @@ -0,0 +1,312 @@ +* [`remove`](#usage-remove) | [`empty`](#usage-empty) | [`replaceWithClone`](#usage-replaceWithClone) +* [`append`](#usage-append) | [`prepend`](#usage-prepend) | [`before`](#usage-before) | [`after`](#usage-after) +* [`replaceWith`](#usage-replaceWith) | [`appendTo`](#usage-appendTo) | [`prependTo`](#usage-prependTo) +* [`insertBefore`](#usage-insertBefore) | [`insertAfter`](#usage-insertAfter) +* [`wrap`](#usage-wrap) | [`unwrap`](#usage-unwrap) + +--- + +## .remove + +**Description** +Removes the set of matched elements from the DOM. + +**Parameters** + +* None. + +**Returns** + +* (jBase): The removed elements (detached). + +**Example** + +```javascript +$('.ads').remove(); + +``` + +--- + +## .empty + +**Description** +Remove all child nodes of the set of matched elements from the DOM. + +**Parameters** + +* None. + +**Returns** + +* (jBase): Current instance. + +**Example** + +```javascript +// 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** + +```javascript +// 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** + +```javascript +$('.list').append('
  • New Item
  • '); + +``` + +--- + +## .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** + +```javascript +$('.list').prepend('
  • First Item
  • '); + +``` + +--- + +## .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** + +```javascript +$('#main').before('
    '); + +``` + +--- + +## .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** + +```javascript +$('#main').after(''); + +``` + +--- + +## .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** +```javascript +$('.old-element').replaceWith('
    Updated
    '); +``` + +--- + +## .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** + +```javascript +$('

    Test

    ').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** + +```javascript +$('

    Intro

    ').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** + +```javascript +$('

    New Alert

    ').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** + +```javascript +$('* Required').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., `
    `). + +**Returns** + +* (jBase): Current instance. + +**Example** + +```javascript +$('.item').wrap('
    '); + +``` + +--- + +## .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** + +```javascript +// Removes the parent
    but keeps the +$('span').unwrap(); + +``` \ No newline at end of file