clientLeft in javascript

clientLeft property in javascript

clientLeft property is used to find the width between the left border and the element.

If the elements text direction is right-to-left, and the element contains scrollbar in left side it will also be added.

When calculating, left margin and padding are not added.


var elem = element.clientLeft;

Example - Get clientLeft of an element

Try Yourself

Example Explanation

  • In the above example we have created a div (idDiv), and have specified border for the element.
  • When the button is clicked, fun_name function is called.
  • In the Javascript function, first we are getting the element (document.getElementById("idDiv")) and storing it in elem variable.
  • Using the clientLeft property, width between the left border and the element is calculated and displayed (alert(elem.clientLeft)).