Click Label, Set Radio Button

26. March 2012 jQuery, UI Stuffs 0
if($('.RadioLabel')[0]){
  $('.RadioLabel').css('cursor', 'pointer');
  $('.RadioLabel').click(function(){
     $(this).parent().find('.FormRadio').attr('checked', true);
  });
}
So, i have a div (.RadioWrapper)  with a radio button (.FormRadio) and a <p> tag (.RadioLabel).  I attach this click event to the label, which calls to the parent of both items to find the associated radio button with class ‘FormRadio’ and sets it to checked.
I could actually just call .prev() on the radio button, but I wasn’t sure if I’d shifted the order anywhere in my app.
you’re path to the elements might be different, but this is a quick way to accomplish this.  sound off in the comments if you hate my guts for doing it this way 🙂
D

Leave a Reply

Your email address will not be published. Required fields are marked *