What it does: jQuery('.choix1').click(function(){ jQuery('#quest1').hide(); When you click on either button related to question 1 it just hides the div id="quest1" What I would like to do is something like: for (i=1; i<=6; i++){ $("choix " + i ).click function(){ $("#quest"+i).hide(); } So every time user clicks on any radio button with id="choix1" or choix2 or choix3... it will hide the related div with id="quest1" or quest 2... Any ideas Thanks for help Jean from France
On 14 mar, 00:57, Josh Powell <seas...@gmail.com> wrote: > What this is doing: > > jQuery('.choix1').click(function(){ > jQuery('#quest1').hide(); > > }); > > is looping through every element on the page with a class of 'choix1', > so you could either change all of the elements you want to loop though > classes to choix and then do > > jQuery('.choix').click(function(){ > jQuery(this).parent().hide(); > > }); > > Which will loop through them all and then hide them when either yes or > no is selected or find some other way of identifying every element > that you want to act on. Perhaps use the name field, or if they are > the only radio buttons on the page you can do > > jQuery(':radio') as the selector. > > On Mar 13, 2:45 pm, macgyver47 <jrl...@wanadoo.fr> wrote: > > > Hi > > I am new to jQuery and learning slowly > > Here is the problem > > I have 6 questions each of them has 2 buttons ( yes or no radio > > buttons) > > When user clicks on 1 answer I would like to hide the entire question > > I have achieved to do this for 1 question but no success looping > > through all 6 questions ! > > <div id="quest1> > > Question 1 > > <input class="choix1" type="radio" name="choix1" > > onclick='q1=1'>Yes<br> > > <input class="choix1" type="radio" name="choix1" onclick='q1=0'>No<br> > > </div> > > <div id="quest2> > > Question 2 > > <input class="choix2" type="radio" name="choix1" > > onclick='q1=1'>Yes<br> > > <input class="choix2" type="radio" name="choix1" onclick='q1=0'>No<br> > > </div> > > ........... > > jQuery('.choix1').click(function(){ > > jQuery('#quest1').hide(); > > }); > > This works for 1 item but how can I loop through all all of them > > Thanks for help > > Jean from France