0

Is it possible to capture the onClick event in a div but ignore any other behavior as pointer-events is set as none?

I have two divs, the background and a kind of a button overlaying this background. I'm capturing a drag event in the background and I need to capture this drag event also if start on the button. I can achieve this just setting my button as pointer-events:none but then I can't capture the onClick on it.

In other words, I have to replicate the behavior of pointer-events:none in JavaScript.

Enzo
  • 4,111
  • 4
  • 21
  • 33
  • 2
    `event.preventDefault` see: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault – Steven Stark Mar 06 '19 at 19:01
  • Applying a preventDefault to all mouse events possible does not have the effect of `pointer-events:none`. I tried with: `click,mousedown,mouseup,dblclick,mousemove,mouseover,mouseout` – Enzo Mar 06 '19 at 20:35
  • sorry let me elaborate. Events bubble. If I click a div, the click event is fired on both the div and on body. If I listen to the click event on the div, and use `e.preventDefault()`, then the body will not receive the event; it will not be bubbled. – Steven Stark Mar 06 '19 at 20:38
  • So I guess is not possible to prevent the div and capture the body event. Is that correct? – Enzo Mar 06 '19 at 20:42
  • AFAIK that is correct, but I'd be happy to find out that I am wrong. – Steven Stark Mar 06 '19 at 21:26

1 Answers1

-1

Try this: Event.preventDefault()

Maor Barel
  • 37
  • 6