English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Ein sehr wichtiger Teil von jQuery ist die Manipulation von DOM-Elementen.
jQuery bietet effektive Methoden zur Manipulation von HTML-Elementen, Attributen und CSS.
Diese Methoden überprüfen und verwalten die Klasseneigenschaften, die einem Element zugewiesen sind:
Methode | Beschreibung |
---|---|
addClass() | 将一个或多个类名称添加到所选元素 |
Add one or more class names to the selected element | hasClass() |
Check if any selected elements have the specified class name | removeClass() |
Remove one or more classes from the selected element | toggleClass()/In addition to |
Copying in
Methode | Beschreibung |
---|---|
This method allows us to copy elements: | clone() |
Surrounding
Methode | Beschreibung |
---|---|
These methods allow us to insert new content around existing content: | wrap() |
Wrap each selected element with an HTML element | wrapAll() |
Wrap all selected elements with an HTML element | wrapInner() |
Internal
Methode | Beschreibung |
---|---|
These methods allow us to insert new content into existing elements: | Insert content at the end of the selected element |
appendTo() | Insert an HTML element at the end of the selected element |
html() | Set or get the HTML content of the selected element |
prepend() | Insert content at the beginning of the selected element |
prependTo() | Insert an HTML element at the beginning of the selected element |
text() | Set or get the text content of the selected element |
These methods allow us to insert new content outside of existing elements:
Methode | Beschreibung |
---|---|
after() | Insert content after the selected element |
before() | Insert content before the selected element |
insertAfter() | Insert an HTML element after the selected element |
insertBefore() | Insert an HTML element before the selected element |
These methods allow us to remove elements from the DOM:
Methode | Beschreibung |
---|---|
detach() | Remove the selected element (retaining data and events) |
empty() | Remove all child nodes from the selected element (including text nodes) |
remove() | Remove the selected element (including data and events) |
unwrap() | Remove the parent element of the selected element |
These methods are used to remove content from the DOM and replace it with new content:
Methode | Beschreibung |
---|---|
replaceAll() | Replace the selected element with a new HTML element |
replaceWith() | Replace the selected element with new content |
These methods get and set the DOM attributes of elements:
Methode | Beschreibung |
---|---|
attr() | Set or return the attribute of the selected element/Value |
prop() | Set or return the attribute of the selected element/Value |
removeAttr() | Remove one or more attributes from the selected element |
removeProp() | Remove attributes set by prop() method |
val() | Set or return the value attribute of the selected element (for form elements) |
Diese Methoden erhalten und setzen CSS-relevante Attribute des Elements:
Methode | Beschreibung |
---|---|
css() | Setzen oder Erhalten einer oder mehrerer Stilattribute für das ausgewählte Element |
height() | Setzen oder Erhalten der Höhe des ausgewählten Elements |
innerHeight() | Setzen oder Erhalten der Höhe des Elements (einschließlich Füllung, aber ohne Rahmen) |
innerWidth() | Setzen oder Erhalten der Breite des Elements (einschließlich Füllung, aber ohne Rahmen) |
offset() | Setzen oder Erhalten der Offset-Koordinaten des ausgewählten Elements (relativ zum Dokument) |
offsetParent() | Rückgabe des ersten positionierten Elternteils |
outerHeight() | Setzen oder Erhalten der Höhe des Elements (einschließlich Füllung, Rahmen und optionaler Margen) |
outerWidth() | Setzen oder Erhalten der Breite des Elements (einschließlich Füllung, Rahmen und optionaler Margen) |
position() | Rückgabe der Position des Elements relativ zum versetzten Elternteil |
scrollLeft() | Setzen oder Erhalten der Position des horizontalen Rollbalkens des ausgewählten Elements |
scrollTop() | Setzen oder Erhalten der Position der vertikalen Rollbalken des ausgewählten Elements |
width() | Setzen oder Erhalten der Breite des ausgewählten Elements |