How Do i handle both the checked and clicked events in Jquery

Posted by Someone on Stack Overflow See other posts from Stack Overflow or by Someone
Published on 2011-01-04T21:50:55Z Indexed on 2011/01/04 21:53 UTC
Read the original article Hit count: 253

Say I have a form and onload of that form I have 2 radio buttons say "yes" or "no " I have set of action to perform when we select either one radio button .Say if we select "yes "

//Onload of Form 
if(("#yes:checked")){
$("#table").show();
$("#div1").show();
$("#div2").show();
alert("Checkedd on Load");
}

//for click

$("#yes").bind('click',function(){ 
    $("#table").show(); 
    $("#div1").show(); 
    $("#div2").show(); 
    alert("Checked by  Click"); }); 
    });

Iam Writing the same repeated lines of code for two similar set of events .Is There anyway to combine the "Checked" and "Clicked" events Say if i do inthis way than "Checked" doesnot get called untill "Clicked"?Is there any other way to do it.

$("#yes").bind('click',function(){
if(("#yes:checked")){
$("#table").show();
$("#div1").show();
$("#div2").show();
alert("Checked by  Click");
}
});
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui