I have a div element that is supposed to be set to display: none by default, but it isn't. It's like the entire .css statement was ignored.
I have 3 files.
index.html, this is where all my buttons and elements are.main.js, this is where the function for toggling tabs (I'm trying to create an idol game) is located at.style.css, this is where small bit of css is located at. I have tried including the css into the mainindex.html, I have tried using the<style>and</style>tags to surround my css and it still doesn't work.
My css file looks something like this:
.hide {
display: none;
}
My include statement looks like this:
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
My div elements look like this:
<div id="ees" class="hide">
<h3>Events</h3>
<span id="log">No events have occured yet</span>
</div>
My JS function for switching tabs looks like this:
function toggle_tab(tabname) {
if(document.getElementById(tabname).style.display == "none")
document.getElementById(tabname).style.display = "block";
else
document.getElementById(tabname).style.display = "none";
}
My button to trigger the event looks like this:
<button onclick="toggle_tab('ees');">Events</button>
The result when running the code is quite weird. The button works, only after pressing it twice instead of once (remember, it is supposed to be set to none by default and pressing it once should reveal it's content). After that, it works fine, but you need to press it twice upon page load, which is an issue. I added this to the function to see what's happening and here are the results:
function toggle_tab(tabname) {
console.log("Display: "+document.getElementById(tabname).style.display);
if(document.getElementById(tabname).style.display == "none")
document.getElementById(tabname).style.display = "block";
else
document.getElementById(tabname).style.display = "none";
}
Here is how the output looks when the first time the button is triggered upon page load.
Display:
That's it. It's like the display: none is ignored in my css class definition.
What I would like is for the console to show display: none when the page loads. This will show a button's content the first time somebody chooses to activate it as well, as the default value will be none upon the beginning of the interaction.
=and their values. For example<div id = "ees" class ="hide">should be<div id="ees" class="hide">.