I have an element, here in the example - $(window). I would like to put several of the same EventListeners on this element, here "scroll" twice. These two EventListeners each perform different functions, which I cannot / do not want to connect with each other, shown here in a simplified manner. How can I delete individual EventListeners?
Here is the little example I made.
// Logs 1 when scrolling
$(window).on("scroll", () => {
console.log(1);
});
// Logs 2 when scrolling
$(window).bind("scroll", () => {
console.log(2);
});
// After 2 seconds stop logging 1
setTimeout(() => {
$(window).unbind("scroll"); // remove only logging 1
}, 2000);
#test {
height:10000px;
width:100vw;
background:blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="test"></div>