vishnu modi
vishnu modi

Reputation: 31

add class of radio button label

<div class="form-radios" id="edit-attributes-1">
<div class="form-item form-type-radio form-item-attributes-1">
 <input type="radio" class="form-radio" value="1" name="attributes[1]" id="edit-attributes-1-1">  <label for="edit-attributes-1-1" class="option">0 </label>

</div>
<div class="form-item form-type-radio form-item-attributes-1">
 <input type="radio" class="form-radio" value="2" name="attributes[1]" id="edit-attributes-1-2">  <label for="edit-attributes-1-2" class="option">2 </label>

</div>
<div class="form-item form-type-radio form-item-attributes-1">
 <input type="radio" class="form-radio" value="3" name="attributes[1]" id="edit-attributes-1-3">  <label for="edit-attributes-1-3" class="option">4 </label>

</div>
<div class="form-item form-type-radio form-item-attributes-1">
 <input type="radio" class="form-radio" value="4" name="attributes[1]" id="edit-attributes-1-4">  <label for="edit-attributes-1-4" class="option">6 </label>

</div>
<div class="form-item form-type-radio form-item-attributes-1">
 <input type="radio" class="form-radio" value="5" name="attributes[1]" id="edit-attributes-1-5">  <label for="edit-attributes-1-5" class="option">8 </label>

</div>
</div>

I have this type structure of radio button in drupal add to cart form. I have to add "active" class on clicked radio button's label (not on radio button) and remove "active" class from other from other clicked radio button's label (not on radio button). Please help.

Thanks

Upvotes: 1

Views: 2170

Answers (2)

Tamil Selvan C
Tamil Selvan C

Reputation: 20199

Try this

$(function() {
    $('.form-radio').on('click', function() {
        $('.form-radio').each(function() { 
             $(this).next().removeClass('active');
        });
        if($(this).is(':checked')) 
            $(this).next().addClass('active');
    });
});

Upvotes: 0

j08691
j08691

Reputation: 207861

$('input[type=radio]').click(function(){
    $('label').removeClass('active');
    $(this).next('label').addClass('active');
});

jsFiddle example

Upvotes: 1

Related Questions