I need to hide all the tags which has the ID ‘media’
E.g.:
`<div id='media'>contents</div>`
`<div id='media'>content</div>`
How to do this using JavaScript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
WOAH slow down there for a second buddy!
ID = IDENTIFIER = UNIQUE
You can only use id’s once
#idCLASS = CATEGORY/GROUP = NOT UNIQUE
You can use classes everywhere
.classas many times as you’d like.Don’t make classes named
.id, that’s silly.Don’t make an id named
#class, as that is also silly.That’ll do it.Apparently no it won’t, read this SO Question about the problem.
jQuery Implementation
Note: All the below examples assume that .hidden is defined in a css file like so:
Hiding Stuff
to hide something by id:
to hide something by class:
to hide everything inside of something:
to hide everything of class
baconwithin the idstomach:Showing Stuff
to show everything that is hidden:
to show everything that is hidden inside of something:
Don’t forget!
You can also use the built in functions,
show()andhide(), like so:They also have some fancyness built in, like basic animation. Refer to the documentation to use those.
It’s best not to mix and match both of these methods, you can easily confuse yourself and waste plenty of time chasing silly mistakes.
Don’t limit yourself!
If you’re new to or unfamiliar with jQuery, don’t forget that you can do things like:
<p>is a vowel, and hide the entire<p>.These are just a few (admittedly silly) examples of the magic jQuery is capable of. There’s a whole book full of new and crazy ways to do things. It’s called the documentation. Don’t be afraid of it because it’s large and full of words. Dive in! There are examples for EVERYTHING. Try things just to try them, even if you don’t think they’ll work (you’ll be surprised).
I’ll only give you the easiest of the five examples. I’ll likely come back to this later and stuff it with more awesomeness.
Hide anything when the user clicks on it:
Wisdom Alert!
Cheesy Pun Warning!