Javascript nodeType

category:web

19.09.2009

Presuming you already know that every page element is a node in a tree called the DOM, it's not hard to imagine there are several types of nodes: attributes of tags, tags, text nodes and so on...

a javascript property of objects let's you determine wich type a node is of, like this:

var nodetype = obj.nodeType;

Returned integer Node type Constant
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



other properties are nodeName wich is supposed to return some human readable form but almost fails at it and nodeValue wich you can use to change node values

Comentarii

+ = Verificare anti-spam

arhiva


comentarii


blogrosfera(5) carte(2) film(11) guestpost(1) internet(4) linkfarm(7) music(3) on_the_road(1) politica(5) quotes(12) seo(2) society(3) spam(8) träume(1) unresolved(1) viata(5) web(8)