Some node acquisition and modification in DOM

Source: Internet
Author: User

1 Get the text object in the tag:

Object. InnerText Get the text content in the tag An unsupported assignment in an earlier Firefox browser will output the escaped content.
Object. InnerHTML Getting all the content assignments in the tag will be output as is. are compatible
Object. textcontent Get the text content in the tag IE8 before including IE8 not supported

2 custom Attribute custom attribute JS cannot be obtained by point

Object. getattribute ("Property name") Get the Custom Property object
Object. SetAttribute ("Property name", "Property value") To set a custom Property object
Object. RemoveAttribute ("Property name") Remove attributes

3 Types of nodes

NodeType node Name The name of the NodeName node NodeValue node Value
Label 1 Label Signature Null
Property 2 Property name Property value
Text 3 #text Text content does not have to be empty

4 How to get nodes

Get attribute Node Object. GetAttributeNode ("Property name") Get attribute Node
Get parent node Element Object. parentnode Get parent node Element
Get son node object. Children Get child node elements (no compatibility issues only get tag elements)
Object. childNodes Get child nodes (including text nodes and label nodes) Text elements are ignored in previous versions of E8
Object. FirstChild First child node
Object. Firstelementchild First child element node IE8 not compatible before
Object. LastChild Last child node
Object. Lastelementchild The most child element node IE8 not compatible before
Get the siblings node NextSibling Next immediate node Next close to the node, Chrome Firefox is supported, but it is possible to get a text node, IE8 and the previous browser will ignore the blank text node, if the text has content, will also get to
Nextelementsibling The next immediate element node,

Both Google and Firefox can get the next immediate element node,
The IE8 and previous versions do not support

PreviousSibling Previous immediate Node The previous node, Chrome Firefox support, but it is possible to get a text node, IE8 and the previous browser will ignore the blank text node, if the text has content, will also get to
Previouselementsibling Previous adjacent Element node

Both Google and Firefox have access to the last element node,
The IE8 and previous versions do not support

Clone node node. CloneNode (True) All include text label elements in the copy node
node. CloneNode (False) Self-replicating node labels
Delete a node The parent element. RemoveChild (child element to delete)
Adding nodes

Parent node. appendchild

(Newborn child node)

Added at the end of the parent element

Parent node. insertbefore

(Newborn child node, a child node)

Increase before a child node

Newly-generated child nodes

Add before a child element

5 Creating nodes dynamically

Some node acquisition and modification in DOM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.