Are you sure you are really warning that top ? Recall that top is an existing global variable in a browser hosted in JavaScript (this is window.top , a top-level window).
Refresh . Interestingly, Chrome won't let you implicitly overwrite top (which is probably good): Demo . Just declare your variable (always a good idea anyway) within any function the code is in (this code is in the function, right?), Which will shadow it, and it will work this way: Demo . For instance:.
var top = $(this).find('ul').position().top;
It is important to declare your variables so as not to fall prey to the Horror of implicit globals . And, as you found in this case, avoiding global bindings is always better, since Chrome will not even allow you to use top as global if you declare it (protect window.top again).
source share