I want to do show/hide div based on dropdown box selection.
And display relevant content / text for each month as in the attached example.
also need after the month passes the option to view the information about it will be automatically removed and so only the relevant content will be displayed.
Can anyone help me with a suitable code please?
2
Answers
Firstly get when user clicks the element
document.getElementById("element").onclick = function()
and in itdocument.getElementById("element").style.display = "none";
none for hiding block for showing.https://www.geeksforgeeks.org/hide-or-show-elements-in-html-using-display-property/
See https://www.w3schools.com/howto/howto_js_tabs.asp for complete code and example
You can do it like this:
I will have a basic explanation of it at the bottom.
First, we create a drop down selector with the name and id of birds, and set the names of birds to it.
We then make a div called birdlist and make it hidden in the css to make all the divs within’ it hidden as well, to make our life easier.
We then create divs for each individual bird with an
tag inside with the innerHTML of the corresponding bird name, and setting a id to them accordingly as well.
Then we create a javascript section and assign the drop down value attribute to the variable e, which we can use in the JS.
We then create a function that will check the drop down value selected by the user with an if statment, and turn the necessary divs visible or invisible as needed.
Finally, we then assign that function as an onclick in the html section of the selectors.
Hope this helps!
js fiddle if needed: https://jsfiddle.net/q0whp3mn/1/