Javascript Scroll Handler not firing

dom-events, event-handling, javascript

Solution

This is because the window is scrolling not the div. Try changing your element listener to the parent of the div (in this case the window) like this.

window.addEventListener("scroll", function () {
    myFunc();
}, false);

Problem

All I'm trying to do is to call a function when a `DIV` is scrolled.For simplicity sake Im not specifying anything else. Also I am only looking at DOM compliant browsers like Chrome, Safari (not IE). MY problem is that the scroll handler never gets called. If I replace the `scroll` to `click` , it works when I click. Somehow the scroll is not working. Please note: I cannot use jQuery :( Here is my code: HTML: ``` <div id="test">--long content--</div> ``` JS: ``` function myFunc() { console.log('in myFunc'); } var objTable = document.getElementById("test"); objTable.addEventListener("scroll", function () { myFunc(); }, false); ``` FIDDLE: http://jsfiddle.net/yymg5/7/

Original source

Related problems