I want a button on my php page to hide and unhide a section on my page. I have this javascript function:
function toggle_filters(){
var x = document.getElementById("filters");
var displayState = x.style.display;
if(displayState == "none")
{
displayState = "block";
}
else {
displayState = "none";
}
}
and i have this html code:
<section id="buttons">
<button id="filter_button">Filters</button>
</section>
<section id="filters">
<form>
<select>
<option>1st option</option>
<option>2nd option</option>
</select>
</form>
</section>
(it is a simplified version)
The problem is that my browser gives me this error:
Uncaught TypeError: Cannot read property 'style' of null
Here is a jsfiddle with my code: https://jsfiddle.net/90wkwn65/2/
I searched the internet but I can't find an answer. Any help would be appreciated!