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

142
Vistas
How can I detect mouseup on top of an element when the click started on a different element?

I'm trying to detect when the mouse is released over a certain html element. I would like the mouseup event to fire no matter where the dragging started initially. Here is my attempt, which behaves very weirdly (sometimes it fires, sometimes not, sometimes I get two alerts):

$("body").click(function() {
  $(".cube").mouseup(function() {
    console.log('mouseup')
  });
});
.box,
.cube {
  background: rgb(255, 0, 0);
  width: 100px;
  aspect-ratio: 1;
  display: inline-block;
}

.cube {
  background: #222;
}
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>

<body>
  <div class="box"></div>

  <div class="cube"></div>
</body>

Problem number 2 demonstrated: the event is not firing after dragging starts from the upper div:

  $(".cube").mouseup(function(){
      console.log('mouseup')
    });
  .box{
        background: rgb(255, 0, 0);
        width: 200px;
        height: 200px;
    }

    .cube{
        background: #222;
        width: 200px;
        height: 200px;
    }
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>

<body>
  <div class="box"></div>

  <div class="cube"></div>
</body>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's even simpler than what you made. You just only need

<script>
     $(".cube").mouseup(function(){
       alert('mouseup')
     });
</script>

If you release it, it means that you have clicked anywhere before

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