jQuery selector for the label of a checkbox
问题 <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) ? 回答1: This should work: $("label[for='comedyclubs']") See also: Selectors/attributeEquals - jQuery JavaScript Library 回答2: $("label[for='"+$(this).attr("id")+"']"); This should allow you to select labels for all the fields