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

134
Vistas
I got = removeChild is not a function

I've trying to remove the disk as a child from a tower as a parent, but this message appears "removeChild is not a function".

let chosenDisc
let chosenTower

disks.forEach((choice) =>
  choices.addEventListener("click", (e) => {
    chosenDisc  = e.target.id
    chosenTower = e.target.parentElement.id
    console.log(chosenDisc, " is in ", chosenTower)
    chosenTower.removeChild(chosenDisc)
    container.appendChild(chosenDisc)
  })
)
<article class="container"></article>
<section class="towers">
  <div class="tower" id="towerOne">
    <div class="disk" id="diskOne"></div>
    <div class="disk" id="diskTwo"></div>
    <div class="disk" id="diskThree"></div>
    <div class="disk" id="diskFour"></div>
  </div>
  <div class="tower" id="torreTwo"></div>
  <div class="tower" id="torreThree"></div>
</section>

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

0

I guess you are attaching an event listener only to elements that have id such as "disk*".

You are picking the id of those elements, and the id of their parent. The ID has no removeChild method, but that method is on the element theirself. In order to make your code work, you should change it as follow:

let chosenDisc
let chosenTower

disks.forEach((choice) => choices.addEventListener("click", (e) => {
    chosenDisc = e.target 
    chosenTower = e.target.parentElement
    console.log(chosenDisc.id, " is in ", chosenTower.id)
    chosenTower.removeChild(chosenDisc)
    container.appendChild(chosenDisc)
}))
about 4 years ago · Juan Pablo Isaza Denunciar

0

In the forEach loop, you are assigning the id of the parent element to chosenTower. chosenTower is not a node, it's just a string.

chosenTower = e.target.parentElement

would fix this.

about 4 years ago · Juan Pablo Isaza Denunciar

0

removeChild and appendChild are expecting a node object. you need to pass the target instead of the target.id for chosenDisc.

let chosenDisc;
let chosenTower;

disks.forEach((choice) =>
   choices.addEventListener("click", (e) => {
     chosenDisc  = e.target;
     chosenTower = e.target.parentElement;
     console.log(chosenDisc, " is in ", chosenTower)
     chosenTower.removeChild(chosenDisc)
     container.appendChild(chosenDisc)
   })
)
<article class="container"></article>
<section class="towers">
  <div class="tower" id="towerOne">
    <div class="disk" id="diskOne"></div>
    <div class="disk" id="diskTwo"></div>
    <div class="disk" id="diskThree"></div>
    <div class="disk" id="diskFour"></div>
  </div>
  <div class="tower" id="torreTwo"></div>
  <div class="tower" id="torreThree"></div>
</section>
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