clientTop in javascript

clientTop property in javascript

clientTop property is used to find the width between the top border and the element.

When calculating, top margin and padding are not added.

Syntax

var elem = element.clientTop;

Example - Get clientTop 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 clientTop property, width between the top border and the element is calculated and displayed (alert(elem.clientTop)).