Toggling an element and its siblings can be accomplished as:
$(this).toggle();
$(this).prev().toggle();
Combining them doesn’t work:
$(this,$(this).prev()).toggle();
How can both be selected at the same time?
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.
Incidentally, while this question has already been answered by drinchev, I thought I’d paste this quick experiment I just did, after reading the question, which also works. Albeit…it surprised me when it did:
JS Fiddle demo.
Incidentally, a JS Perf loose comparison of the two selector approaches.
Edited to add an IE-(so far as I know)-friendly update, albeit I’m currently saddling all browsers with it, rather than feature-detecting (also, I finally realised that blue != green):
JS Fiddle demo