I'm learning jQuery and this is my code so far:
<script type="text/javascript">
$(document).ready(function(){
$('#login').click(function(){
$('#login-box').fadeIn('fast');
});
});
</script>
It works, when you click the login button the DIV called login-box
shows on the page. What I wanted to do was if the login button was clicked again, the login-box
DIV will fade from the page. What would be the best way to do this? I was thinking:
$(document).ready(function(){
$('#login').click(function(){
if(login-box-is-showing)
{
$('#login-box').fadeOut('fast');
} else {
$('#login-box').fadeIn('fast');
}
});
});
But I'm confused at how I would determine if the DIV is showing or not. I also see that jQuery has a toggle function, would that be better?
Thanks.