views:

2687

answers:

2
<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) ?

+9  A: 

This should work:

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

See also: Selectors/attributeEquals - jQuery JavaScript Library

Kip
+3  A: 

This should do it:

$("label[for=comedyclubs]")

If you have non alphanumeric characters in your id then you must surround the attr value with quotes:

$("label[for='comedy-clubs']")
Darko Z