modify the name of an input with jquery

2

Someone can help me, I am dynamically creating elements dynamically inputs with the .clone () method with jquery but I want to change the name of the input that clono, for example if I have the following input

This is the input that clono

<input class="form-control" type="text" id="inputTemplate" name="inputTemplate">

After cloning I want to change the name, for example to:

 <input class="form-control" type="text" id="inputclonado" name="inputclonado">
    
asked by Alejandro.C 31.05.2018 в 18:31
source

1 answer

2

It's a matter of using the .attr(...) method: JQuery attr .

Example (I would also recommend that you change the id after cloning it):

var elementoClonado = $("#" + id).clone()
elementoClonado.attr('id', 'nuevo id');
elementoClonado.attr('name', 'nuevo nombre');
    
answered by 31.05.2018 / 18:37
source