Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda