Element clientLeft Property - Javascript DOM

Javascript examples for DOM:Element clientLeft

Description

The clientLeft property returns the size of left border of an element, in pixels.

This property is read-only.

Return Value

A Number, representing the size of an element's left border, in pixels

The following code shows how to get the width of a <div> element's top and left border:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*  www . j a  v  a 2 s .  c o  m*/
    height: 250px;
    width: 400px;
    padding: 10px;
    margin: 15px;
    border-top: 15px solid black;
    border-left: 10px solid red;
    background-color: lightblue;
}
</style>
</head>
<body>

<p>Click the button to get the width of the div's top and left border, in pixels.</p>

<button onclick="myFunction()">Test</button>

<div id="myDIV">
  <p id="demo"></p>
</div>

<script>
function myFunction() {
    var elmnt = document.getElementById("myDIV");
    var txt = "Border top width: " + elmnt.clientTop + "px<br>";
    txt += "Border left width: " + elmnt.clientLeft + "px";
    document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

Related Tutorials