Sharing of DOM knowledge points in js

小云云
Release: 2018-03-14 16:41:24
Original
1408 people have browsed it

1. childNodes and nodeType

childNodes gets the child nodes, but the space between one label and another label will be calculated as text nodes. nodeType determines what type of node a node is. Only when nodeType==1 is the element node, 2 is the attribute node, and 3 is the text node.
2. Children gets child nodes. It only returns HTML nodes, not even text nodes. Although it is not a standard DOM attribute, it is the same as the innerHTML method and is supported by almost all browsers.
3. offsetParent obtains the positioned parent element node of the node.
4. FirstChild() and firstElementChild() have compatibility issues. Use if to deal with compatibility issues. The rest of lastchild and so on are similar to this.
5. Use dom to get element attributes, use setAttribute('attribute to be set', 'set attribute value'), removeAttribute(name), getAttribute(name), which are basically not commonly used. But there are also situations where it must be used.
6. Using className to select elements can encapsulate a simple method. This is a low version now and has no bugs, but it has strong limitations.

    

Copy after login

7. Create nodes such as forum functions
Be sure to add the created node to his parent element
creatElement() to create the node
appendChild() to add the created node to his parent element before
insertBefore() in a certain Insert a node before
removeChild() to delete a node

   创建节点  

Copy after login

Related recommendations:

Some summary of using DOM

Deep into the advanced application of DOM in JavaScript

Summary of native JavaScript operations on dom nodes

The above is the detailed content of Sharing of DOM knowledge points in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!