Hiding elements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

Hiding elements

How can I hide an element if the player clicks a certain button?

8th Feb 2017, 2:00 PM
Caleb Jore
Caleb Jore - avatar
5 Answers
+ 8
Thanks a lot!
8th Feb 2017, 2:14 PM
Caleb Jore
Caleb Jore - avatar
+ 5
From your question, two actions need to be carried out. The first being the user interaction and the second, hiding the element. User interaction is handled by events, either inlined or in a script. button.addEventListener('click', hideElement, false); function hideElement() { element.style.display = 'none'; } The display property determines if the element will show up on the page. This is not to be confused with the visibility property. The latter allows the element to still take up space but the former totally hides it. Read on event listeners to grasp its concept and understand what arguments it can take.
8th Feb 2017, 2:24 PM
John
John - avatar
+ 2
add on click listener to a button and write something like that in it: document.getElementById("elementToHide").style.display = "none";
8th Feb 2017, 2:11 PM
Jakub Stasiak
Jakub Stasiak - avatar
+ 2
learn jquery if u don't know js. (jquery belongs to js). but easier to leaarn
10th Feb 2017, 12:36 AM
Faisal Imran
Faisal Imran - avatar
- 1
l
21st Feb 2017, 4:00 PM
[No Name]