Good day!

Help in solving the issue.

I have blocks with input type="radio"

The structure is as follows

 <div class="wrapper_all_radio0"> <input type="radio" id="radio01" name="radio" /> <input type="radio" id="radio02" name="radio" /> <input type="radio" id="radio03" name="radio" /> </div> 

I need the name to change to the name of the class div, i.e. name="wrapper_all_radio0" for all inputs inside this diva

And yet, each new block with the class wrapper_all_radio0 changes javascript, i.e. the first block has a wrapper_all_radio0 class, the second block has a wrapper_all_radio1 class, etc.

Thus, it is necessary to compare the name of the diva and assign the corresponding name to all the inputs within each diva.

Changing the class diva performs the following code

 $(function(){ $('.wrapper_all_radio').each(function(i){ var $tc = $(this).attr('class') $(this).attr('class', $tc+i) }) }) 

Thanks in advance for your help! )

    1 answer 1

    You can find elements inside the div using the .find() method. It takes a selector, so to find the switches, you can give it a selector 'input[type="radio"]' :

     $(function(){ $('.wrapper_all_radio').each(function(i){ var $tc = $(this).attr('class') $(this).attr('class', $tc+i) $(this).find('input[type="radio"]').attr('name', $tc+i) }) }) 
    • one
      Thank you very much! - Alexey Yarygin