edzillion edzillion - 10 months ago 44
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:


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>



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 Source

works for me