What are the differences between parentnode, parentelement, and offsetparent in JavaScript?

Source: Internet
Author: User

Offsetparent directly affects the upper-level element of the element position, while the upper-level element in the Dom is irrelevant to the position display.
For example:

  < Body >
< Div Style = "Border: 1px solid black; position: absolute ;" >  
< Form >  
< Input Type = "Checkbox" ID = "Cc"   />  
</ Form >  
</ Div >  
  </ Body >

 

In this example, the offsetparent of the "cc" element is Div. If the position attribute of the DIV is removed, the CC offsetparent will be changed to the body. While parentelement is always form.
There are also offsetleft and offsettop attributes, which indicate the distance between the left and top of the element.

The parentnode and parentelement functions the same, while the childnodes and Children functions the same. However, parentnode and childnodes comply with W3C standards and are more common. The other two are only supported by IE, but not by Firefox.

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.