How can I make the drop down list disappear when I click on the button again ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How can I make the drop down list disappear when I click on the button again ?

https://code.sololearn.com/WX8s4DllXr9b/?ref=app

1st Nov 2020, 4:48 PM
Francisco Bensaia
Francisco Bensaia - avatar
3 Answers
+ 5
1st Nov 2020, 5:20 PM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 3
On the onclick attribute of button, just call a function like this : <button onclick="toggle ()" > menu </button> Now in JavaScript file, write the following code : let visible = false; function toggle(){ if (visible){ document.getElementById('list').style.display='none'; visible = false; } else{ document.getElementById('list').style.display='flex'; visible = true; } }
1st Nov 2020, 5:21 PM
Ameer Haider
Ameer Haider - avatar
+ 1
1.way: create js function which chenges x value from 1 to 0 and from 0 to 1 each time button clicked and set property display: none; 2.way: use CSS hidden checkbox labeled as button. when checkbox selected display: flex; when unchecked display: none.
1st Nov 2020, 5:20 PM
Shadoff
Shadoff - avatar