javascript - How to debug why a jQuery function is not working? -


i have been trying simple function work using callback don't understand doing wrong. want invoke function when scrolltop greater zero. new programming , can't figure out.

is formatting issue?

function alertme() {     var $window = $(window);     var window_top = $window.scrolltop(0);      if (window_top > 0) {         alert("alertme");     }; }; 

you can use scrolltop() method capture current scroll top , attach handler scroll, -

$(window).scroll(function (e) {     if($(window).scrolltop()>0) {         alert("alertme");     } }); 

Comments