Get the position of the background-image in a <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundPosition

Description

Get the position of the background-image in a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button type="button" onclick="myFunction()">Get background position</button>
<br>
<div id="myDiv" style="background: url('http://java2s.com/resources/a.png') no-repeat center;height:500px;width:500px;border:1px solid black;">
</div>/*from  ww  w  . ja  v a  2  s .c  om*/

<script>
function myFunction() {
    console.log(document.getElementById("myDiv").style.backgroundPosition);
}
</script>

</body>
</html>

Related Tutorials