<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
border: 1px solid black;
width: 400px;
height: 200px;
background: url("w3css.gif") no-repeat;
}
</style>
</head>
<body>
<h1>Change background-repeat with JavaScript</h1>
<p>Click the "Try it" button to set the background-repeat property of the DIV element to "repeat-x":</p>
<button onclick="myFunction()">Try it</button>
<br><br>
<div id="myDIV">
<h1>Hello</h1>
</div>
<script>
function myFunction() {
document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";
}
</script>
</body>
</html>