Basic tutorial for JavaScript operations on HTMLDOM nodes _ basic knowledge

Source: Internet
Author: User
This article mainly introduces the basic tutorials for JavaScript operations on HTMLDOM nodes, including operations such as creating, modifying, and deleting nodes. It also mentions appendChild () and insertBefore () when inserting a node, you need to pay attention to this issue. For more information, see the DOM. This allows you to use JavaScript to obtain, create, modify, or delete a node.
NOTE: The elements in the example below are all element nodes.
Get Node

Parent-child relationship

element.parentNodeelement.firstChild/element.lastChildelement.childNodes/element.children

Sibling relationship

element.previousSibling/element.nextSiblingelement.previousElementSibling/element.nextElementSibling

Obtaining nodes through the direct relationship between nodes greatly reduces code Maintainability (the changes in the relationship between nodes directly affect the nodes to be obtained), and the interface can effectively solve this problem.

Obtaining nodes through the direct relationship between nodes greatly reduces code Maintainability (the changes in the relationship between nodes directly affect the nodes to be obtained), and the interface can effectively solve this problem.

 
  ELEMENT_NODE & TEXT_NODE 
 
 
  • First
  • Second
  • Third
  • Fourth

Hello

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.