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

119
Views
Avoid hiding a div when selecting text with a wide swipe

I have a div hided that shows and hide cliking on a buttom (toogle). This div also hides whatever you click anywhere in the document. And finally I also have an stopPropagation click function event on the div so it won't hide when you click on it. All these is working as expected

The input inside the div is a search field that shows results on real time while users are writting and often the users select whatever text they are writting to edit or delete it.

My problem is that when the users are selecting the text and swipe out of the field (while pressing the mouse buttom) the div will automatically hide.

How could I prevent this?

I hope I have explained myself well enough, this may be quiete a confused question.

This is a working example. Just writte anything inside and select it:

$('.input').click(function(e) {
  e.stopPropagation();
})

$('.button').click(function(e) {
  $('.input').slideToggle('fast');
  e.stopPropagation();
})
$(document).on("click", function() { 
  $('.input').slideUp('fast');
});
html {margin-left:100px;}
.button {
  height:50px;
  width:50px;
  background-color:red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="button">
</div>
<div id="divBuscar" class="input" style="display: none;">
  <input type="text" id="txtBuscar" name="txtBus" placeholder="Buscar productos, promociones, novedades...">
  <a id="btnBuscar"></a>
</div>

Ty.

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

0

I'm ashamed I didn't thought about mousedown property.

it works just changing the script like this:

$('.input').mousedown(function(e) {
  e.stopPropagation();
})

$('.button').mousedown(function(e) {
  $('.input').slideToggle('fast');
  e.stopPropagation();
})
$(document).on("mousedown", function() { 
  $('.input').slideUp('fast');
});
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!