JavaScript adding opacity to page

I have a page with a background image and six tiles that are links, All of those are contained in a <div id = "main">. I also have a side navbar that pushes the content to the right when clicked on.
I want to also add some opacity to #main, but i am stuck.
Below is my javascript code for my Side Navbar where I am trying to change the backgroundColor, which I know is clearly wrong. Is there a way to add opacity to an entire page?

document.getElementById("myBtn").addEventListener("click", toggleNav);

function toggleNav(){
    navSize = document.getElementById("mySidenav").style.width;
    if (navSize === "400px") {
        return close();
    }
    return open();
}
function open() {
        document.getElementById("mySidenav").style.width = "400px";
        document.getElementById("main").style.marginLeft = "400px";
        document.getElementById("main").style.backgroundColor = "yellow";
}
function close() {
        document.getElementById("mySidenav").style.width = "0";
        document.getElementById("main").style.marginLeft = "0";
        document.getElementById("main").style.backgroundColor = "white";
}
Answer:1

I am working on Angular2 project and got an issue that Chrome caches HTML templates. It is not a problem for the development since I can make cache to be ignored in Chrome Dev mode. But it is a real ...

I am working on Angular2 project and got an issue that Chrome caches HTML templates. It is not a problem for the development since I can make cache to be ignored in Chrome Dev mode. But it is a real ...

I have an array of object. Each item has a paret id mentioned. I want to create a nested object where it nesting goes on as much as the subcategories. Input and expected output given below. How can I ...

I have an array of object. Each item has a paret id mentioned. I want to create a nested object where it nesting goes on as much as the subcategories. Input and expected output given below. How can I ...

Consider the following: function filterFoods() { var foods = [ {food: 'Bacon'}, {food: 'Butter'}, {food: 'Chicken'}, {food: 'Cocoa butter'}, {food: 'Saussages'}, {food: 'Ham'}, {food: ...

Consider the following: function filterFoods() { var foods = [ {food: 'Bacon'}, {food: 'Butter'}, {food: 'Chicken'}, {food: 'Cocoa butter'}, {food: 'Saussages'}, {food: 'Ham'}, {food: ...

Iam trying to start my script after another script finished his work and returned rt():adv.bind to console. The script is running in an iframe. I tried it with window.addEventListener but the script ...

Iam trying to start my script after another script finished his work and returned rt():adv.bind to console. The script is running in an iframe. I tried it with window.addEventListener but the script ...