jquery - JavaScript global variable in function and .hover -


i have code in javascript:

status = document.getelementbyid('status2');  $('#slider > img').hover(     function() {         stoploop();         status.innerhtml = "paused";     },      function() {         startslider();         status.innerhtml = "playing";     } ); 

where images in html have id slider , when hover on want add word (paused or playing) span tag has id status2. don't know why global variable not working, way make work putting local variable inside each funcion this:

function() {     stoploop();     var status = document.getelementbyid('status2');     status.innerhtml = "paused"; }, function() {     startslider();     var status = document.getelementbyid('status2');     status.innerhtml = "playing"; } 

can me why?

note: said before works local variables not setting global variable.

because time run

status = document.getelementbyid('status2'); 

dom not ready status undefined , wont work further.

so either put code in ready

$(document).ready(function(){    //code goes here }) 

or

put script @ end of file.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -