Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
How to drag and drop before or after element using java

I am building a drag and drop website. But I'm facing a problem to drop the element before or after, above or below the other element. I have watched a tutorial about it that's working but I cannot attach the code to my code as I'm totally new to java. Here is my drag and drop code:

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

function drag(ev) {
  ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev) {
  ev.preventDefault();
  var data = ev.dataTransfer.getData("text");
  ev.target.appendChild(document.getElementById(data));
}
#div1, #div2 {
  float: left;
  width: 200px;
  height: 300px;
  margin: 10px;
  padding: 10px;
  border: 1px solid black;
}
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">

<button  draggable="true" ondragstart="drag(event)" id="drag1">btn1</button>
<button  draggable="true" ondragstart="drag(event)" id="drag2">btn2</button>
<button  draggable="true" ondragstart="drag(event)" id="drag3">btn3</button>
 
</div>

<div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)"></div>

Answer in javascript please

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!