English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery HTML/CSS-Methode

Ein sehr wichtiger Teil von jQuery ist die Manipulation von DOM-Elementen.

jQuery bietet effektive Methoden zur Manipulation von HTML-Elementen, Attributen und CSS.

Klasseneigenschaft

Diese Methoden überprüfen und verwalten die Klasseneigenschaften, die einem Element zugewiesen sind:

MethodeBeschreibung
addClass()将一个或多个类名称添加到所选元素
Add one or more class names to the selected elementhasClass()
Check if any selected elements have the specified class nameremoveClass()
Remove one or more classes from the selected elementtoggleClass()/In addition to

Toggle one or more classes between the selected element

Copying in

MethodeBeschreibung
This method allows us to copy elements:clone()

DOM insertion-Create a deep copy of the selected element

Surrounding

DOM insertion-Wrap each selected element's content with an HTML element

Internal

MethodeBeschreibung
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

DOM insertion-External

These methods allow us to insert new content outside of existing elements:

MethodeBeschreibung
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

DOM removal

These methods allow us to remove elements from the DOM:

MethodeBeschreibung
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

DOM replacement

These methods are used to remove content from the DOM and replace it with new content:

MethodeBeschreibung
replaceAll()Replace the selected element with a new HTML element
replaceWith()Replace the selected element with new content

General attributes

These methods get and set the DOM attributes of elements:

MethodeBeschreibung
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)

Stilmethoden

Diese Methoden erhalten und setzen CSS-relevante Attribute des Elements:

MethodeBeschreibung
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