Differences between tagname and nodename

Source: Internet
Author: User
Tags tagname

The tagname and nodename have the same semantics and both return the names of the included tags. For example, the above H2 tags all return H2, but tagname can only be used on element tags, nodename can be used on all nodes. The values of nodename on different nodes are as follows:

Interface Nodename Nodevalue Attributes
ATTR Name of attribute Value of attribute Null
Cdatasection # CDATA-Section Content of the CDATA section Null
Comment # Comment Content of the comment Null
Document # Document Null Null
Documentfragment # Document-Fragment Null Null
Documenttype Document Type name Null Null
Element Tag Name Null Namednodemap
Entity Entity name Null Null
Entityreference Name of entity referenced Null Null
Notation Notation name Null Null
Processinginstruction Target Entire content excluding the target Null
Text # Text Content of the text node Null

Tagname has a value only on the element node.

From the DOM level, nodename is the property on the node interface, while tagname is the property on the element interface. All nodes (12 types of element nodes, attribute nodes, and text nodes) only the Element Node inherits the element node. Therefore, nodename has a larger scope of use than tagname.

Conclusion: tagname can only be used on element nodes, while nodename can be used on any node. It can be said that nodename covers tagname and has more functions. Therefore, we recommend that you always use nodename.

Differences between tagname and nodename

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.