The ClientX event property returns the horizontal coordinates of the mouse pointer to the browser page (or client area) when the event is triggered.
The client area refers to the current window.
If the parent div's position is defined as relative, and the position of the child Div is defined as absolute, then the style.left value of the child div is relative to the parent Div, which is the same as the offsetleft, except that:
1. Style.left returns a string, such as 28px,offsetleft returns a value of 28, and if the value obtained is calculated, it is more convenient to use offsetleft.
2. Style.left is read-write, offsetleft is only readable, so to change the location of the Div, can only modify the Style.left.
3. The value of style.left needs to be defined beforehand, otherwise the value taken is null. and must be defined in HTML, I have done experiments, if the definition in CSS, style.left value is still empty, this is the problem I started to encounter, always do not get the value of Style.left. Offsetleft can still be fetched without having to define the div's location beforehand.
The above is the Div offsetleft and style.left difference data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!