I have a page in which there are multiple hrefs. i want to find out which href is clicked and based on that href click I want to show and hide a div?
Share
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.
I’m going to assume you have control over the href’s here and you want to have the simplest markup possible, in that case you can do something like this:
Then to open/toggle a div based on the
href, or more specifically thehashproperty, you can do this:This toggles the corresponding
<div>with the matchingID == hrefminus the hash and hides the other<div>elements if that’s what you’re after…you do this by just giving them a common class and hide all those except the one related to the current link.You can view a demo here to see if it’s what you’re after.