Search code examples
javascripthtmlcssbackgroundopacity

Javascript remove background color and opacity


How can I remove the background-color and opacity property using Javascript only (no Jquery!).

I tried this:

document.getElementById('darkOverlay').style.removeProperty("background-color");
document.getElementById('darkOverlay').style.removeProperty("opacity");

but it did not work.


Solution

  • You can just reset properties by either setting them to an empty string:

    document.getElementById('darkOverlay').style.backgroundColor = "";
    document.getElementById('darkOverlay').style.opacity = "";
    

    Or setting them to the default values you like:

    document.getElementById('darkOverlay').style.backgroundColor = "transparent";
    document.getElementById('darkOverlay').style.opacity = "1";