left Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:left

Description

The left property sets or gets the left position of a positioned element.

Property Values

Value Description
autoLets the browser set the left position. This is default
length Defines the left position in length units. Negative values are allowed
% Sets the left position in %?of the width of the parent element
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: auto
Return Value: A String, representing the left position of a positioned element
CSS VersionCSS2

Get the left position of a <button> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<div id="myDiv" style="position:absolute;left:255px;">This is a div element.</div>

<button type="button" onclick="myFunction()">Return left position of div</button>

<script>
function myFunction() {/*from  w  w  w .  j  a  v  a2s.  com*/
    console.log(document.getElementById("myDiv").style.left);
}
</script>

</body>
</html>

Related Tutorials