HTML DOM nodeType-Eigenschaft
Beispiele
Gibt den Knotentyp des body-Elements zurück:
Ausgabe:
Selbst ausprobieren »
Definition und Verwendung
Die nodeType-Eigenschaft gibt den Knotentyp zurück.
Wenn der Knoten ein Elementknoten ist, gibt die nodeType-Eigenschaft 1 zurück.
Wenn der Knoten ein Attributknoten ist, gibt die nodeType-Eigenschaft 2 zurück.
Wenn der Knoten ein Textknoten ist, gibt die nodeType-Eigenschaft 3 zurück.
Wenn der Knoten ein Kommentarknoten ist, gibt die nodeType-Eigenschaft 8 zurück.
Diese Eigenschaft ist schreibgeschützt.
Browser-Unterstützung
![]()
![]()
![]()
![]()
![]()
Alle gängigen Browser unterstützen die nodeType-Eigenschaft
Syntax
Technische Details
| Rückgabewert: | String, der den Knotentyp des Knotens repräsentiert. |
|---|---|
| DOM-Version | Core-Level-1-Node-Objekt |
Knotentypen
Ein HTML- oder XML-Dokument, seine Elemente, Attribute usw. haben unterschiedliche Knotentypen.
Es gibt 12 verschiedene Knotentypen, und verschiedene Knotentypen können auch unterschiedliche Kindknotentypen haben:
| Knotentyp | Beschreibung | Kindknoten | |
|---|---|---|---|
| 1 | Element | Ein Element | Element, Text, Comment, ProcessingInstruction, CDATASection, Entity Reference |
| 2 | Attr | Ein Attribut | Text, Entity Reference |
| 3 | Text | Der Textinhalt eines Elements oder Attributs | Keine |
| 4 | CDATASection | Ein CDATA-Abschnitt eines Dokuments (Text wird nicht vom Parser geparst) | Keine |
| 5 | Entitätsreferenz | Entitätsreferenz | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference |
| 6 | Entität | Eine Entität | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference |
| 7 | ProcessingInstruction | Eine Verarbeitungsanweisung | Keine |
| 8 | Kommentar | Ein Kommentar | Keine |
| 9 | Dokumentation | Das gesamte Dokument (der Wurzelknoten des DOM-Baums) | Element, ProcessingInstruction, Comment, DocumentType |
| 10 | DocumentType | Stellt eine Schnittstelle für Dokumententitäten bereit | Keine |
| 11 | DocumentFragment | Repräsentiert benachbarte Knoten und deren Teilbäume. | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference |
| 12 | Notation | Repräsentiert eine Deklaration einer Notation in der DTD | Keine |
Knotentypen – Rückgabewerte
Gibt den Knotennamen und den Wert der nodeValue-Eigenschaft für jeden Knotentyp zurück:
| Knotentyp | Rückgabewert von nodeName | Rückgabewert von nodeValue | |
|---|---|---|---|
| 1 | Element | Elementname | null |
| 2 | Attr | Attributname | Attributwert |
| 3 | Text | #text | Knoteninhalt |
| 4 | CDATASection | #cdata-section | Knoteninhalt |
| 5 | Entitätsreferenz | Entity-Referenzname | null |
| 6 | Entität | Entitätsname | null |
| 7 | ProcessingInstruction | target | Knoteninhalt |
| 8 | Kommentar | #comment | Kommentartext |
| 9 | Dokumentation | #document | null |
| 10 | DocumentType | Doctype-Name | null |
| 11 | DocumentFragment | #document fragment | null |
| 12 | Notation | Notationsname | null |
Knotentypen - Statische Variablennamen
| Knotentypen | Benannte Konstante |
|---|---|
| 1 | ELEMENT_NODE |
| 2 | ATTRIBUTE_NODE |
| 3 | TEXT_NODE |
| 4 | CDATA_SECTION_NODE |
| 5 | ENTITY_REFERENCE_NODE |
| 6 | ENTITY_NODE |
| 7 | PROCESSING_INSTRUCTION_NODE |
| 8 | COMMENT_NODE |
| 9 | DOCUMENT_NODE |
| 10 | DOCUMENT_TYPE_NODE |
| 11 | DOCUMENT_FRAGMENT_NODE |
| 12 | NOTATION_NODE |
Andere Erweiterungen
Element-Objekt