Why does this function get fired without having clicked on the specified button? I had a look at a few similar problems but none deal with this code structure (might be obvi
You are directly calling it.
document.getElementById("main_btn").addEventListener("click", hideId("main");
You should do that in a callback.
document.getElementById("main_btn").addEventListener("click", function (){ hideId("main"); });