0
How do i make text show up by tapping it?
How do i make "tap to display text"? something like <p onclick="showHelper()" >Main text</p> <p id='text' style="display: none;">Secondary text</p> <script> function showHelper() { document.getElementById('text').style.display = 'block'; } </script> but work more than one time i want it like Section 1 Part 1 Text Part 2 Text Part 3 Text Section 2 Part 1 Text Part 2 Text Part 3 Text But to open each one you tap it And when you tap it again it closes Can you do the code for me please?
2 Answers
+ 1
you can do something like this:
document.getElementById("myElement").onclick = function(){
if(this.display == "block"){
this.display = "none";
}else{
this.display = "block";
}
}
This checks if the display is block, which will hide the element if it is. If it is already hidden, it will set display to block. Hope this helps!
+ 1
you can do this for multiple elements. It shouldn't rely on other external vars.