The difference between Div.offersetleft and Div.left

Source: Internet
Author: User

If the position of the parent div is defined as relative, the position of the child Div is defined as absolute, then the style.left value of the child div is relative to the value of the parent Div, which is the same as offsetleft, except that:

1. Style.left returns a string, such as 28px,offsetleft returns a value of 28, it is convenient to use offsetleft if the obtained value is to be calculated.

2. Style.left is read-write, offsetleft is only readable, so to change the position of Div, can only modify Style.left.

3. The value of style.left needs to be defined beforehand, otherwise the value taken is null. and must be defined in the HTML, I have experimented, if defined in the CSS, the value of Style.left is still empty, this is the problem I just started to encounter, always do not get the value of Style.left.

The offsetleft is still available without having to define the div's position in advance.


The difference between Div.offersetleft and Div.left

Related Article

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.