Javascript DOM CSS Style backgroundPosition Property set to top right

Introduction

Change the position of a background-image:

document.body.style.backgroundPosition = "top right";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {/*from   w w  w .  jav a  2  s .  co m*/
  background-image: url('image1.png');
  background-repeat: no-repeat;
}
</style>
</head>
<body>

<button type="button" onclick="myFunction()">Position background image</button>

<script>
function myFunction() {
  document.body.style.backgroundPosition="top right";
}
</script>

</body>
</html>



PreviousNext

Related