Change class and name to an input depending on a radio input with jquery

0

Having a code like this:

<input type="radio" id="campo_1">
<input type="text" class="hidden" name="campo_1">

<input type="radio" id="campo_2">
<input type="text" class="hidden" name="campo_2">

I want, for example, having :checked radius #campo_1 remove the hidden class from the input with name campo_1 and change the name to micampo

What would be the best way?

$('#campo_1').click(function(){
     if ($('#campo_1').is(':checked'){
      //aquí es donde no tengo ni idea de como hacerlo...
     }
});

Or is there a better way?

    
asked by Pavlo B. 02.01.2017 в 10:19
source

1 answer

1

Try this:

$("#campo_1").change(function(){
if ($("#campo_1").is(':checked')) { 
      $("[name='campo_1'").removeClass('hidden').attr('name', 'micampo')
    }
});
    
answered by 02.01.2017 / 10:53
source