Within my current jQuery code, I wanted to make possible to animate to the top of my webpage and dropdown a hidden element right afterwards. The problem is that I am using an if statement to check wether this element is hidden, but my code runs twice through that if statement, causing the dropdown to slide up immediately after sliding down.
When I run the following code:
$("a#drop-user-box").click(function()
{
$("html, body").animate({scrollTop: 0}, "slow", function()
{
alert("foo");
});
return false;
});
It will pop an alert and when I click e.g. the "Ok" button, another alert pops open (meaning the code runs twice). Can anyone explain me why this is happening?
When I add the alert like so:
$("a#drop-user-box").click(function()
{
alert("foo");
//$("html, body").animate({scrollTop: 0}, "slow", function()
//{
//});
//return false;
});
It will run the code (in this (example) case the alert) once (but not afterwards).