Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop scroll event from propagating with javascript?

Tags:

javascript

Lets take this simple example:

HTML:

<div id="A">
    <div id="B">
    </div>
</div>

When user moves mouse to the element B and starts to scroll, the element A should not get scroll event. How to disable scroll event from propagation?

EDIT: I've tried this js code and it does not work. Any ideas?

document.getElementById("B").scroll = function(e) {e.stopPropagation();}
like image 806
pawelczak Avatar asked Oct 19 '22 20:10

pawelczak


1 Answers

The event.stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent event handlers from being executed.

https://developer.mozilla.org/en/docs/Web/API/Event/stopPropagation

like image 135
Swarnendu Paul Avatar answered Oct 21 '22 17:10

Swarnendu Paul