DOM manipulation methods
The DOM manipulation methods are discussed in detail in Chapter 5, Manipulating the DOM.
Attributes and properties
Manipulation method |
Description |
---|---|
|
Gets the attribute named |
|
Sets the attribute named |
|
Sets the attribute named |
|
Sets attribute values given as key-value pairs. |
|
Removes the attribute named |
|
Gets the property named |
|
Sets the property named |
|
Sets the property named |
|
Sets property values given as key-value pairs. |
|
Removes the property named |
|
Adds the given class to each matched element. |
|
Removes the given class from each matched element. |
|
Removes the given class if present, and adds it if not, for each matched element. |
|
Returns |
|
Gets the value attribute of the first matched element. |
|
Sets the value attribute of each element to |
Content
Manipulation method |
Description |
---|---|
|
Gets the HTML content of the first matched element. |
|
Sets the HTML content of each matched element to value. |
|
Gets the textual content of all matched elements as a single string. |
|
Sets the textual content of each matched element to |
CSS
Manipulation method |
Description |
---|---|
|
Gets the CSS attribute named |
|
Sets the CSS attribute named |
|
Sets CSS attribute values given as key-value pairs. |
Dimensions
Manipulation method |
Description |
---|---|
|
Gets the top and left pixel coordinates of the first matched element, relative to the viewport. |
|
Gets the top and left pixel coordinates of the first matched element, relative to the element returned by |
|
Gets the vertical scroll position of the first matched element. |
|
Sets the vertical scroll position of all matched elements to |
|
Gets the horizontal scroll position of the first matched element. |
|
Sets the horizontal scroll position of all matched elements to |
|
Gets the height of the first matched element. |
|
Sets the height of all matched elements to |
|
Gets the width of the first matched element. |
|
Sets the width of all matched elements to |
|
Gets the height of the first matched element, including padding, but not border. |
|
Gets the width of the first matched element, including padding, but not border. |
|
Gets the height of the first matched element, including padding, border, and optional margin. |
|
Gets the width of the first matched element, including padding, border, and optional margin. |
Insertion
Manipulation method |
Description |
---|---|
|
Inserts
|
|
Inserts the matched elements at the end of the interior of the elements matched by |
|
Inserts |
|
Inserts the matched elements at the beginning of the interior of the elements matched by |
|
Inserts
|
|
Inserts the matched elements after each of the elements matched by |
|
Inserts |
|
Inserts the matched elements before each of the elements matched by |
|
Wraps each of the matched elements within |
|
Wraps all of the matched elements as a single unit within |
|
Wraps the interior contents of each of the matched elements within |
Replacement
Manipulation method |
Description |
---|---|
|
Replaces the
matched elements with |
|
Replaces the elements matched by |
Removal
Manipulation method |
Description |
---|---|
|
Removes the child nodes of each matched element. |
|
Removes the matched nodes (optionally filtered by |
|
Removes the matched nodes (optionally filtered by |
|
Removes the element's parent. |
Copying
Manipulation method |
Description |
---|---|
|
Makes a copy of all matched elements, optionally also copying event handlers. |
Data
Manipulation method |
Description |
---|---|
|
Gets the data
item named |
|
Sets the data item named |
|
Removes the data item named |