My code is :
$(document).ready(function(){
var hCount = 0,
eCount = 0,
nCount = 0,
mCount = 0;
$("#head").click(function() {
var pPos = counter(hCount);
$(this).animate({left:pPos+"px"}, 1000);
});
function counter(count)
{
count++;
if(count === 10)
{
count = 0;
pPos = 0;
}
else
{
var pPos = $(this).css('left');
pPos = pPos.substring(0,(pPos.length-2))
pPos -= 367;
}
return pPos;
}
Uncaught TypeError: Cannot read property 'defaultView' of undefined
counter()
$(this)
$("#head").click
$("#head")
#head
Just extend counter function with elem
argument and pass it within click handling:
function counter(count, elem){
// ...
}
$("#head").click(function() {
var elem = $(this);
var pPos = counter(hCount, elem);
elem.animate({left:pPos+"px"}, 1000);
});