Reputation: 1386
I am looking for a solution for following:
For JQuery: How can I change the attribute of all parents of objects that have the same name?
Here is my code:
<div class="roundedOne">
<input type="radio" id="id_single" name = "radStatus" value = "1" />
<label for="id_single"></label>
</div>
<div class="roundedOne">
<input type="radio" id="id_married" name = "radStatus" value = "1" />
<label for="id_single"></label>
</div>
I want to do something like : $("[name='radStatus']").parent().attr("class", "myNewClassName");
Thanks :)
Upvotes: 1
Views: 58
Reputation: 399
You can use the .parents() jQuery method.
So this:
$("[name='radStatus']").parent().attr("class", "myNewClassName");
Becomes this:
$("[name='radStatus']").parents().attr("class", "myNewClassName");
Here is a working Fiddle that will change all the parents of the elements. Inspect the elements to see the new class name.
Upvotes: 1
Reputation: 121998
Try
$("input[name ='radStatus']").parent().addClass("myNewClassName");
Upvotes: 1