What is the HTML ClientLeft property?
ClientLeft is an HTML DOM property that returns the width of the left border of any element. However, it does not include the padding or the margin that is defined for the element.
Code
The following code finds the width of the left border of the div:
Explanation
-
Line 5: We define
border-leftand thebackground-colorfor the CSS IDleft. -
Line 15: We hook the
change()method to theonClickevent of a button. -
Line 17: We define a
divwith IDleft. -
Line 23: We define the
change()function. We usedocument.getElementById()to get thedivelement with IDleft. -
Line 25: We get the left border width of the
div, using theclientLeftmethod. -
Line 26: We print the value of the left border width to the console.