Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore click on div

I have set an "onmousedown" event handler for the body of my page. In this page there are some div elements, is it possible to ignore the clicks on these divs, and to just fire the onmousedown event handler of the body with the correct coordinates, as if the divs were not present?

like image 331
Sean Avatar asked May 28 '15 14:05

Sean


People also ask

How do I stop a click in HTML?

To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element.

How do you stop a click event in CSS?

To disable a link using CSS, pointer-events property can be used, which sets whether the element in the page has to respond or not while clicking on elements. The pointer-events property is used to specify whether element show to pointer events and whether not show on the pointer.

How to prevent event capturing?

To stop an event from further propagation in the capturing and bubbling phases, you call the Event. stopPropation() method in the event handler. Note that the event. stopPropagation() method doesn't stop any default behaviors of the element e.g., link click, checkbox checked.


1 Answers

If you want a click on a div to result in nothing, use this CSS declaration:

div {
pointer-events: none;
}

or use this to stop any event from firing by a click on a div:

$('div').click(function(e) {
  e.stopPropagation();
});
like image 166
Friendly Crook Avatar answered Sep 20 '22 12:09

Friendly Crook