I know I might be doing something wrong. Can anyone please point out why I’m getting top as object??
$(document).ready(function(){
topwithpx='0px';
alert(topwithpx);
topstr=topwithpx.substr(0,topwithpx.length-2);
alert(topstr);
top=parseInt(topstr);
alert(top);
});
Thanks all: ‘top’ is reserved keyword (Window.top). My bad. Accepting first ans. +1 to all for quick ans.
Because it’s essentially
window.top, which is Window object. Usevar topinstead to prevent mixing local variable with global (= properties ofwindowobject) ones.In fact, make
var-ing your function variables something of a common routine – to prevent getting similar gotchas in the future. )