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

248
Views
Opposite of ondragover in javascript?

I am making a drag and drop application for which the user drags a file into a div. When the file that is being dragged is over the div, the div turns green.

var dropzone = document.querySelector(".dropzone");

dropzone.ondragover = event => {
  event.target.classList.add("fileover");
};
.dropzone {
  border: 1px solid lightgray;
  padding: 2rem;
  margin: 2rem;
  border-radius: 10px;
  font-family: Arial;
  cursor: pointer;
  text-align: center;
  font-size: 0.8rem;
}

.fileover {
  background-color: green;
}
<input id="file" type="file" style="display: none"/>
<label for="file">
  <div class="dropzone" ondrop="event.preventDefault()">Drag and drop or select a file</div>
</label>

But let's say, the user decides not to drop the file into the drop zone and moves the file away from the drop zone. In that case, the drop zone stays green. So is there an event that fires when the file goes away the drop zone, so then, the drop zone turns white again? Something like ondragaway?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use ondragleave :

Note that I also replace ondragover with ondragenter for the sake of consistensy.

var dropzone = document.querySelector(".dropzone");

dropzone.ondragenter = event => {
  event.target.classList.add("fileover");
};

dropzone.ondragleave = event => {
  event.target.classList.remove("fileover");
};
.dropzone {
  border: 1px solid lightgray;
  padding: 2rem;
  margin: 2rem;
  border-radius: 10px;
  font-family: Arial;
  cursor: pointer;
  text-align: center;
  font-size: 0.8rem;
}

.fileover {
  background-color: green;
}
<input id="file" type="file" style="display: none"/>
<label for="file">
  <div class="dropzone" ondrop="event.preventDefault()">Drag and drop or select a file</div>
</label>

about 4 years ago · Juan Pablo Isaza Report
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!