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

249
Visualizações
Drag and drop a button into a table

Im new to JS and HTML, but I hope this doesnt sound dumb now. Ive got a list on the right side where a bunch of buttons are shown which I want to be able to drag and drop them into the empty table on the left side.

What I done already:

With the code I got atm i get this error

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

So I already found that the method is returning a string instead of a node element and this method can only append elements with that type. So how do I move the input as a node element? Are there better ways to do that?

JavaScript:

function allowDrop(event) {
  event.preventDefault();
}

function drag(event) {
  event.dataTransfer.setData("text", event.target.id);
  console.log(data);
}

function drop(event) {
  event.preventDefault();
  var data = event.dataTransfer.getData("text");
  event.target.appendChild(document.getElementById(data).value);
  console.log(data);
}

Script for the button list

@foreach (var t in ct.cases)
{
<div class="database-cases" data-tooltip="@t.Title" draggable="true" ondragstart="drag(event)" id="dragbutton">
  <input class="database-cases-id btn btn-link" type="button" value="@t.IdText" onclick="" />
  <sub class="database-cases-title">@t.Title</sub>
</div>
}

Table:

<table class="overallTable" summary="Layout" ondrop="drop(event)" ondragover="allowDrop(event)" id="dropzone"></table>
about 4 years ago · Juan Pablo Isaza
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