Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
Error trying to overlay and remove elements with removeChild

i have a problem in the following code snippet.

for (var i=0;i<data.parlist.length;i++){
            var inp = document.createElement("input")
            var label = document.createElement("label")
            var labelValue = document.createElement("label")
            var subDiv = document.createElement("div")
            var br = document.createElement("br")
            try{
                var dBtn = document.getElementById(data.parlist[i].id);
                var dLabel = document.getElementById(data.parlist[i].id + " label")
                
                var dDiv = document.getElementById(data.parlist[i].id +" div");

                var inprad = document.getElementById(data.parlist[i].id+" inp_rad");
                var dLabelRad = document.getElementById(data.parlist[i].id + " label_rad")

                var dSubDiv = document.getElementById(data.parlist[i].id +" div_rad");

                dSubDiv.replaceChild(inprad);
                dSubDiv.removeChild(dLabelRad);

                dDiv.removeChild(dSubDiv);
                
                dDiv.removeChild(dBtn);
                dDiv.removeChild(dLabel);
                
                myDiv.removeChild(dDiv);
                
            }catch{
                console.log("no")
            }

This for loop is inside a function that when clicking on a button of a station shows the parameters.in this way:

enter image description here

Shows station parameters

What you see in the images works, but the problem that I have come to try to clarify is that when I press the button for example as station 1 appears in the image and then I press the button for example of station 2 the try that is supposed to you must remove the previous parameters with removeChild does not work, the parameters of station 1 remain in the div and the parameters of station 2 are added below these instead of being removed

Shows how the parameters are added below the other parameters

Within the try there is a problem but I do not know what it is, I say this because when I check the page and open the console I get the message that I left in the catch a "no"

The "no" on the console

Thanks for reading my problem and any suggestions are welcome as I am desperate to find a solution.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to pass 2 inputs to the replaceChild function.

parentNode.replaceChild(newChild, oldChild);

For more info refer Mozilla docs here.

Here is some additional advice

  1. When you log for debugging, use some meaningful messages. In your case you could do
try {
 ...
} catch (err) {
   console.log(err);
}
  1. From the questions nothing is clear about what is there in data.parlist and whether that is implemented properly.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda