edzillion edzillion - 19 days ago 5
jQuery Question

hide() radio button *and* its text label in jquery

I am going back over a recent project sorting out accessibility issues and was making sure all form elements had labels. Putting the label text into a tag caused a problem with some kludgy code I had written before.

Basically, if you have a radio button and its label:

<label for="zone_r1"><input type="radio" name="zone" id="zone_r1" value="NY" />New York</label>


And you use jquery to hide it like so:

$('#zone_r1').hide();


The actual button is hidden but not the label text. Originally I made a span for the label text and hid that like so:

<input id="NY" type="radio" name="zone" value="NY" /><span id="nyTXT">New York</span>


and

$('#NY').hide();
$('#nyTXT').hide();


Any ideas? I prefer not to use the kludge and it may not validate with the span in the label, but maybe I am being overly zealous.

Answer
$('#zone_r1').parent().hide();

works for me

Comments