Hello!
im new to html and Javascript and wanted to create a button which makes my frame visible and invisible.
I googled a lot and could make text invisible and visible but that has not worked with my frame! : /
The “frame” is a div class.
The CSS visibility:hidden ensures the <div> is initially hidden. However it does not set the element’s .style.visibility property to “hidden”. I have therefore used not equal (!=) in the function to ensure the visibility changes on the first click of the button.
Note the addEventListener needs to come after the HTML for the button. This is why I have put the JavaScript after the HTML for the elements. When the page loads into a browser the addEventListener is executed but the function is not executed until the button is clicked.
but i have one question, can i use a class instead of an id? I usually use Classes : )
Greetings. And do i need to add the script in the Html or can i link the Script file too ?
Maybe i have too many Questions, and maybe its the wrong topic but is there a way to add Buttons and Images in this Box which will dissapear too, or do i have to make a script for every Part?
Thank You!
Did you test the example given to you by @Archibald and see what happens when you add buttons and images inside the #frame div?
If you make the parent visibility:hidden then all the children will be hidden also (unless they explicitly have visibility:visible applied). Note that visibility does not remove the element from the flow. It just makes it invisible. If you want the space to collapse then display:none would be a better choice.
e.g. Roughly:
It is unclear from your html what you are trying to achieve as that html is badly formed. It looks as though you are trying to click <button id="Research">Doge Labor</button> and then you want to show this : <div class="ToggleResearch"></div> based on the js you are using.
However you changed the id of ToggleResearch to a class so the js can no longer find it.
frm = document.getElementById("ToggleResearch");
You would need an ID in the html.
<div id="ToggleResearch"></div>
The js will then show that ToggleResearch div but as it is empty then no one will know!!
You would need content inside that div if you want to show something.
e.g.
<div id="ToggleResearch">Now you see ME</div>
You should use headings in logical order as you cannot jump from an h1 to an h6.