OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Javascript Scroll Handler not firing

  • Thread starter Thread starter Sajjan Sarkar
  • Start date Start date
S

Sajjan Sarkar

Guest
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:

Code:
<div id="test">--long content--</div>

JS:

Code:
   function myFunc() {
        console.log('in myFunc');
    }
    var objTable = document.getElementById("test");

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

FIDDLE:

http://jsfiddle.net/yymg5/7/

<p>All I'm trying to do is to call a function when a <code>DIV</code> is scrolled.For simplicity sake Im not specifying anything else. Also I am only looking at DOM compliant browsers like Chrome, Safari (not IE).</p>

<p>MY problem is that the scroll handler never gets called. If I replace the <code>scroll</code> to <code>click</code> , it works when I click. Somehow the scroll is not working.</p>

<p>Please note: I cannot use jQuery :(</p>

<p>Here is my code:</p>

<p><strong>HTML:</strong></p>

<pre><code><div id="test">--long content--</div>
</code></pre>

<p><strong>JS:</strong></p>

<pre><code> function myFunc() {
console.log('in myFunc');
}
var objTable = document.getElementById("test");

objTable.addEventListener("scroll", function () {
myFunc();
}, false);
</code></pre>

<p><strong>FIDDLE:</strong></p>

<p><a href="http://jsfiddle.net/yymg5/7/" rel="noreferrer">http://jsfiddle.net/yymg5/7/</a></p>
 

Latest posts

G
Replies
0
Views
1
Gamal Othman
G
Top