You can add a partial attribute to the selector.

Try this:

$('[id$=_y]').click() and $('[id$=_n]').click()

This will select any elements that have an ID ending in '_y' and '_n'
respectively.  If this is too broad or specific, alter the selectors
accordingly.

Also, this is unrelated to your problem, but you can select more than
one element at once, and shorten your code.  You can make:

                $('#questions').hide();
                $('#questionLink').hide();

into
                $('#questions,#questionLink').hide();


and you can do the same thing everywhere else you have more than one
hide(), show(), click(), etc.
Hope I was able to help you.
~ross.

On Aug 25, 2:21 pm, the intern <[email protected]> wrote:
> Hey All
>
> On my page I have a table with a list a questions whose answers are
> just yes or no. What I need to do is when the user clicks the radio
> button "yes" a table element will show with some additional questions.
>
> My problem is, I have 26 different yes - no questions all of which
> will have different "id's" for each radio button and table element. Is
> there a way to make my jQuery code dynamic so that I do not have to
> repeat it over and over again with each of the different id's?
>
> Here is the jQuery I have now, it works for the first question, but
> how do I get this same set of code to work for all the question with
> their different id's?
>
> In the code : 1a_y is the id for the yes radio button
>                     1a_n is the id for the no radio button
>
> <script type="text/javascript">
> $(document).ready(function(){
>                 $('#questions').hide();
>                 $('#questionLink').hide();
>         $('#1a_y').click(function(){
>                 $('#questions').show();
>                 $('#questionLink').show();
>                 $('#1a_y').checked(true);
>                 return false;
>                 });
>         $('#1a_n').click(function(){
>                 $('#questions').hide();
>                 $('#questionLink').hide();
>                 $('#1a_n').checked(true);
>                 return false;
>                 });
>         $('#toggle1a').click(function(){
>                 $('#questions').toggle();
>                 return false;
>                 });});
>
> </script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to