document.style.backgroundImage - How to have DIV without content show full background image

24 views Asked by At

I need to add in a full width banner on a specific page on a WordPress website so I figured DOM Manipulation would be the way to go...

The banner, is just an image. Nothing else.

The only way, so far, that I can get the image to show is to put in some content using innerHTML...

Is there another way to get an empty div with a background image to just be the size of the background image?

const websiteNav = document.getElementById("nav");
    
const banner = document.createElement("div");
    
banner.innerHTML = '<br>';
banner.style.backgroundImage = "url('https://www.website.com/images/image.png')";

websiteBanner.appendChild(banner);
0

There are 0 answers