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

215
Views
How to detect before dropped selected text into input

As usual you can drop selected text from anywhere into inputs. I want to do something when cursor into an input. ex: if I selected some text then I dragged into an input, but I don't dropping into that input. But input making the cursor and the cursor icon has been changed to plus icon, I want to do function at that time!

enter image description here


$("input").on("beforeDROP", function(){
//do something
});
    form input {
        font-size: 16px;
    }

    form {
        margin: 0 auto;
        width: 100%;
        text-align: center;
    }
    <form>
        <p>some text</p>
        <input type="text" />
    </form>

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

0

You can use the dragover and dragstart events to listen for these events.

Attaching a dragstart listener to the document will fire whenever any selected text is dragged on the page.

If you add a dragover listener to your text input you'll be able to detect when the selected text is being dragged over it:

let textInput = document.getElementById('text-input');

textInput.addEventListener("dragover", (event) => {
  // prevent default to allow drop
  event.preventDefault();
  
  console.log('dragging over input');
}, false);


document.addEventListener("dragstart", (event) => {
  console.log('dragging');
}, false);
form input {
  font-size: 16px;
}

form {
  margin: 0 auto;
  width: 100%;
  text-align: center;
}
<form>
  <p>some text</p>
  <input type="text" id="text-input" />
</form>

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!