Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda