I want to make a div visible if there is an element on the page. For example:
If ('#some_div') is on the page, I want to do a ('#another_div').show();
What’s the syntax to make this happen?
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.
You can use
.length, like this:.lengthreturns the number of results the selector found, if it found any it’s greater than 0 (true) andfalseotherwise.Alternatively if you need to hide it, e.g. so it works both ways, you can use
.toggle(bool)like this:This works regardless of the initial state, it’ll hide it if
#some_divisn’t not there, and show it if it is.