The difference _javascript skill between parentnode,parentelement,childnodes,children in JS

Source: Internet
Author: User

Parentelement gets the parent object in the object hierarchy.
ParentNode gets the parent object in the document hierarchy.
ChildNodes gets a collection of HTML elements and Textnode objects that are direct descendants of the specified object.
Children gets a collection of DHTML objects that are direct descendants of an object.

--------------------------------------------------------

Like ParentNode and parentelement functions, childnodes and children function as well. But ParentNode and childnodes are consistent with the standard of the Global Consortium, which can be said to be more generic. While the other two are only IE support, not the standard, Firefox does not support

--------------------------------------------------------

Use this parentnode,childnodes 2 to be OK. The upstairs are all positive solutions!

--------------------------------------------------------

Is it just a different standard?

--------------------------------------------------------

This is not "standard",
The other two is not a standard at all,
Can be understood as IE customization

--------------------------------------------------------

That is to say parentelement, children is ie own thing, the other place is not recognized.
Well, their standard version is parentnode,childnodes.
These two functions are the same as parentelement and children, and are standard and universal.

--------------------------------------------------------

Here is a simple explanation to note the differences in individual words:
ParentNode property:retrieves The Parent object in the document hierarchy.

Parentelement Property:retrieves The Parent object in the object hierarchy.

ChildNodes:
Retrieves a collection of HTML Elements and Textnode objects that are direct descendants of the the specified object.

Children
Retrieves a collection of DHTML Objects that are direct descendants of the object.

--------------------------------------------------------

I also took two paragraphs from the DHTML manual ^_^
Parentelement Children:
There is no public standard the applies to this property/collection.
ParentNode childnodes:
This is defined into world Wide Web Consortium (property/collection) Document Object Model (DOM) Level 1.

Many of the standards for the standard of the consortium began to support IE5
IE4 used to only use IE's own method

============================================

<div id= "Test1" > bbb<div>aaa</div> <div>aaa</div> </div> <script> alert ( document.getElementById ("Test1"). Childnodes.length); Alert (document.getElementById ("Test1"). Children.length); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

See, this BBB here, it's affecting the results.

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.