JS Operation Dom of the increase and deletion check

Source: Internet
Author: User

JS nodes are divided into three types:

ELEMENT Node 1
Attribute Node 2
Text Node 3

JS add element node:

innerHTML should be the most efficient way, of course, can also be created using document.createelement way, through AppendChild or Parentnode.insertbefore (newele,targetele ) to add ELEMENT nodes

JS Delete element node:

Parent.removechild (Ele)

JS Change or delete the attributes of an element node

SetAttribute RemoveAttribute

JS change the text value of the element node:

1: You can get the text node of the element node first, and then the text node has a property that is nodevalue, by changing the value of nodevalue to achieve the purpose of modifying the text of the element node

2: Through the element node InnerText property to achieve the purpose, but innertext will return the text including the child elements, and at the time of modification, if the element node contains child elements, will also be erased, outertext modification will delete the element itself

JS Gets the element node:

Get parent node: parentnode

Get first child node: FirstChild

Get Last child node: LastChild

Get previous sibling node: previoussibling

Get the latter sibling node: nextSibling

Get all types of child nodes: Childrennode returns all types of nodes, depending on whether the node's NodeType is a filter in all ELEMENT nodes

Get all child element nodes: Children only returns child element nodes, attribute nodes and text nodes do not return (IE8 will return comments as nodes)

JS to determine if a child node is included: Contains

  

JS Operation Dom of the increase and deletion check

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.