Various ways to manipulate HTML Dom Properties __html

Source: Internet
Author: User
The 1.element.getattribute (AttributeName) method returns the property value of the specified property name, and the type returned is a string type

The 2.element.getattributenode (AttributeName) method obtains an attribute node (a node with a NodeType value of 2) from the current element node (a node with a NodeType value of 1) by name. The return value is the specified property node

The 3.element.setattribute (Attributename,attributevalue) method adds the specified property and assigns the specified value to it. If this specified property already exists, only the value is set/changed, and no return value 4.element.setattributenode (Attributenode) method is used to add the specified attribute node to the element. If this specified property already exists, this method replaces it

the 5.element.removeattribute (AttributeName) method is used to delete the specified property. No return value Note: The difference between this method and the Removeattributenode () method is that the Removeattributenode () method deletes the specified Attr object, and this method deletes the property with the specified name. The results are the same. Also, this method does not return a value, and the Removeattributenode () method returns the Deleted property, in the form of a Attr object The 6.element.removeattributenode (Attributenode) method is used to delete the specified property and to return the deleted property with the Attr Node object. Return value is an object of type attr The 7.element.hasattribute (AttributeName) method is used to determine that if a specified property exists, the Hasattribute () method returns True, otherwise it returns false The 8.node.hasattributes () method is used to determine whether the node (not just element node elements) owns the property, and the owning property returns TRUE, otherwise it returns false. If the specified node is not an element node, the return value is always false. Note: **-Node (node) is the generic name for any type of object in the DOM hierarchy, and node has many types, such as element nodes (elements), attribute nodes (attr), text nodes (texts), annotation nodes (comments), and so on. Differentiate by NodeType The **-element inherits the node class, meaning that the element is one of the various types of node, that is, when NodeType node is Elementnode, and the other element extends Node,element owning ID, class, children and other attributes **-Simply put, node is a base class, and Element,text and comment in the DOM inherit from it. In other words, element,text and comment are three special NODE, respectively called Element_node, Text_node and Comment_node So why is the following "document.body.childNodes.length" The result is 9?

In fact, node represents the structure of the DOM tree, in HTML, the node and the node can be inserted between the text, the insertion of the gap is Text_node

This is logical, the body's immediate element (3) + Comment_node (1) + text_node (5) = 9 Note: We found nodelist with ChildNodes, But when we manipulate the DOM, we tend not to manipulate node (I just want to manipulate element elements), so how do I get elementlist? The getelementsbyxxx that we often use returns a elementlist, except that its real name is ElementCollection . Just as NodeList is a set of node, ElementCollection is also a collection of element. But the special note: NodeList and elementcollcetion are not real arrays. If document.getElementsByTagName (' a ') instanceof Array, then it must be false.

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.