$(document).ready(function(){
$("#cbox").hover(function()
{
$(this).stop(true,false)
//.animate({right: 0}, 500); },function()<-- invalid syntax: leave out parentheses and semi-colon:
.animate({right: 0}, 500,function()
{//no need for the selecot here
$(this).stop(true,false).animate({right: -120}, 500);
});
});
$('.storeItems').on('click',function()
{//best use on for AJAX content, for example
$('#cbox').trigger('hover');/
});
});//you were missing this closing
There's one suggestion I'd like to make: the .on('click'
handler has a jQuery selector in it. This means that you'll scan the DOM on each click event for that #cbox
element. You can make your code more efficient by using a closure here:
$('.storeItems').on('click',(function(cbox)
{
return function()
{//cbox is a reference to the cart element, in memory so no need to scan the dom over and over
cbox.trigger('hover');
};
}($('#cbox'))));//pass the reference here
I know, there's a lot of function
's and even more parentheses and brackets. You don't have to use this approach, but just keep this in the back of your mind as you go about learning more JS: you'll start using closures sooner or later, I promise :)