How to style background image to no repeat with JavaScript DOM?

HTMLJavascriptProgramming Scripts

To style the background image to no repeat with JavaScript, use the backgroundRepeat property. It allows you to set whether the background image repeats or not on a page.

Example

You can try to run the following code to learn how to style background image to no repeat with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Click to Set background image</button>
      <script>
         function display() {
            document.body.style.backgroundImage = "url('https://www.tutorialspoint.com/html5/images/html5-mini-logo.jpg')";
            document.body.style.backgroundRepeat = "no-repeat";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 05:17:10
Advertisements