JavaScript - AYUDA por favor, Crear boton para eliminar Child.

 
Vista:
sin imagen de perfil

AYUDA por favor, Crear boton para eliminar Child.

Publicado por Diego (6 intervenciones) el 06/09/2016 14:28:15
HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<div id="bloque">
 
  <input type="text" placeholder="Número de unidades">
 
    <select>
      <option>1000 - PAN</option>
      <option>1010 - SALCHICHA</option>
      <option>1020 - COCA-COLA</option>
    </select>
 
  <input type="text" placeholder="Costo por unidad">
 
<input type="button" value="Eliminar" onclick="eliminar()">
 
</div>
 
<div id="destino"></div>
 
<input type="button" value="Agregar" onclick="agregar()">

JAVASCRIPT

1
2
3
4
5
6
7
8
9
10
11
12
13
function agregar(){
	var element = document.getElementById("bloque");
	var copy = element.cloneNode(true);
	var destino = document.getElementById("destino");
	destino.appendChild(copy);
}
function eliminar(){
	var element = document.getElementById("bloque");
	var copy = element.cloneNode(true);
	var destino = document.getElementById("destino");
 
	element.removeChild(destino);
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alain
Val: 26
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

AYUDA por favor, Crear boton para eliminar Child.

Publicado por Alain (8 intervenciones) el 06/09/2016 20:34:40
Hola trata con esto. Suerte!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<head runat="server">
    <title></title>
    <script type="text/javascript">
 
        function agregar() {
            var element = document.getElementById("bloque");
            var copy = element.cloneNode(true);
            var destino = document.getElementById("destino");
            destino.appendChild(copy);
        }
        function eliminar(event) {
            var element = event.target;
            var parent = element.parentNode;
            parent.remove();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="bloque">
 
  <input type="text" placeholder="Número de unidades"/>
 
    <select>
      <option>1000 - PAN</option>
      <option>1010 - SALCHICHA</option>
      <option>1020 - COCA-COLA</option>
    </select>
 
  <input type="text" placeholder="Costo por unidad"/>
 
<input type="button" value="Eliminar" onclick="eliminar(event)"/>
 
</div>
 
<div id="destino"></div>
 
<input type="button" value="Agregar" onclick="agregar()"/>
    </div>
    </form>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

AYUDA por favor, Crear boton para eliminar Child.

Publicado por Diego (6 intervenciones) el 06/09/2016 23:04:32
Man eres un máquina, me ha funcionado de maravilla. Te lo agredezo de verdad. Un abrazo!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar