javascript - Reaching variables in jQuery -
i have code :
<script type="text/javascript"> var currentpicture;//default picture var picel;//the image viewer element jquery("#backimageshower").hover( function(i) { picel = jquery("#dynloadarxdock > img"); currentpicture = picel.attr("src"); picel.attr("src","back.jpg"); }, function() { picel.attr("src",currentpicture); } ); </script>
but when run code, says picel
not defined. think because of closures code runs :
<script type="text/javascript"> var currentpicture;//default picture jquery("#backimageshower").hover( function(i) { currentpicture = jquery("#dynloadarxdock > img").attr("src"); jquery("#dynloadarxdock > img").attr("src","back.jpg"); }, function() { jquery("#dynloadarxdock > img").attr("src",currentpicture); } ); </script>
but code includes global variable , works.
can tell me why?
thanks.
the problem you're mixing casing. variable declared picel
used picel
(lowercase 'l', error is).
Comments
Post a Comment