There is a code:

$('.js-radio').click(function(){ var active = 'form__radio--active'; $(this).addClass(active); $('.js-radio').parents('.js-radio--block').find('.js-radio').not(this).removeClass(active); }); 

How to restrict his work outside the '.js-radio--block' ?

If there is only one such block on the page, then there are no problems. If multiple, it does not work correctly. The principle of operation is required <input type="radio">

Thank you in advance!

http://codepen.io/anon/pen/oxVQVN

  • Add the html code to the question - Vasily Barbashev
  • it looks like $(this).parents . but for now this is speculation - splash58
  • It seems like $(this).parent('.js-radio--block') Why are all parents? or even closest('.js-radio--block') - Jean-Claude
  • oh yes parent, if not even closest - splash58
  • 2
    @ Vasily Barbashev, but sometimes there is such room for fantasy. After all, it is possible to solve something more complicated :) break away from the routine :)) - splash58

1 answer 1

It is solved this way http://codepen.io/anon/pen/yOwZaN But theoretically you should understand that different groups of radiobuttons should be given different names, I don’t know how you will process them further, but keep in mind later.

 $(function() { $('.js-radio').click(function() { var active = 'form__radio--active'; $(this).addClass(active); $(this).closest('.js-radio--block').find('.js-radio').not(this).removeClass(active); }); });