views:

367

answers:

2

I have a div having a css class "MyClass". Inside this div, I can have any number of checkboxes immediately followed by an anchor having some specific text (lets say MyText for the example).

How can I select all the checkbox elements using JQuery. What I have is

$('div.givenclass input:checkbox')."I DON"T KNOW WHAT TO PUT HERE"

I want to make sure the the checkboxes I get are immediately before an anchor tag with text "MyText".

Please help!

+3  A: 
$("div.MyClass a:contains(specific test)").prev(":checkbox");
cletus
Thanks, that worked
A: 

This will check all checkbox matching it

$('div.givenclass input:checkbox').attr('checked', true);

To restrict before 'my text' achor you can do .prev or check for elements in .each, but better would be to group related checkbox in a div, and select all checkbox in that div

Anurag Uniyal