How to set the background image for an element with JavaScript DOM?

HTMLJavascriptProgramming Scripts

To set the background image in JavaScript, use the backgroundImage property. It allows you to set the background image.


You can try to run the following code to learn how to set the background image with JavaScript −

Live Demo

<!DOCTYPE html>
      <button onclick="display()">Click to Set background image</button>
         function display() {
   = "url('')";
Updated on 23-Jun-2020 10:01:07