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?
1 Answer 1
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);
});