I have this global variable which is used as counter which I want to access in the jquery hover function. But some how the variable is throwing “undefined” error when I try to access it in the hover function. The code is
var i = 0
$('#ticker-area').hover(function() {
alert(i); //THROWS UNDEFINED ERROR
clearTimeout(t1);
if (i > 0) {
alert(i); //NEVER REACHES HERE
var i = i - 1;
var innerText = tickerItems[i];
i++;
}
$('#ticker-area').html(innerText);
}, function() {
clearTimeout(t1);
rotateTicker();
});
Please help.
Thanks
Paddy
If you are new to javascript always use http://www.jslint.com/ to check your code.
Checking your code I get the following errors:
Problem at line 1 character 10: Missing semicolon. var i = 0 Problem at line 8 character 15: 'i' is already defined. var i = i - 1; Problem at line 12 character 28: 'innerText' used out of scope. $('#ticker-area').html(innerText);So