I am facing a challenge in updating the existing background-image with a linear gradient. Currently, my CMS is generating a background-image, but I am unable to adjust the opacity using a linear gradient. My goal is to darken the background-image using CSS.
Here is my approach -> Extracting the URL from all div elements with the class of "bg-image" to then use the "setAttribute" method to apply a new background-image property.
var elems = document.getElementsByClassName("bg-image");
for (var i = 0, n = elems.length; i<n; ++i){
var img = document.getElementsByClassName('bg-image')[i],
bi = style.backgroundImage.slice(4, -1);
img.setAttribute('style', 'background-image: linear-gradient( rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5),url("' bi +'"));');};