jQuery selector for the label of a checkbox

Darwyn picture Darwyn · Jul 27, 2009 · Viewed 251.9k times · Source
<input type="checkbox" name="filter" id="comedyclubs"/>
<label for="comedyclubs">Comedy Clubs</label>

If I have a check box with a label describing it, how can I select the label using jQuery? Would it be easier to give the label tag an ID and select that using $(#labelId) ?

Answer

Kip picture Kip · Jul 27, 2009

This should work:

$("label[for='comedyclubs']")

See also: Selectors/attributeEquals - jQuery JavaScript Library