1

I am doing the following to toggle the display of an element:

$("*[id^=" + id + "_]").toggle(); // id is the element to toggle

This then toggles everything of the form id_* where * is any string.

I now realized, that I don't want to simply toggle each element, but show or hide it based on the state of the clicked element. How can I conditionally show() or hide() all those elements of the form 'id_*' depending on some other boolean? My problem is that the selector automatically selects multple id's, so how I can I trigger a show() or hide() selectively on each id that is selected?

asked Aug 20, 2010 at 13:09

1 Answer 1

3

You can pass a bool to .toggle() to tell it whether to show and hide, so just look through, like this:

$("*[id^=" + id + "_]").each(function() {
 var someBool = condition; //figure out each one here, depending on...whatever
 $(this).toggle(someBool);
});
answered Aug 20, 2010 at 13:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.