Javascript DOM CSS Style backgroundRepeat Property set

Introduction

Change the backgroundRepeat property of a specified DIV element:

document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";

Click the button to set the background-repeat property of the DIV element to "repeat-x":

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//w ww .j a v a2 s. co m
  border: 1px solid black;
  width: 300px;
  height: 150px;
  background: url('image1.png') no-repeat;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="myDIV">
<h1>Hello</h1>
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";
}
</script>

</body>
</html>



PreviousNext

Related