Reputation: 311
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!
Upvotes: 1
Views: 2179
Reputation: 88865
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
Upvotes: 0