First, add an ID to your hyperlink to make it easier to attach event handlers...
<a id="toggle" href="javascript:void(0);">forgot password?</a>
<div id="login-form"></div>
<div id="recover-password" style="display:none;"></div>
Then, write a bit of script to wire up a click event. We'll use the jQuery toggle()
helper to attach handlers for both states:
$(function() // run after page loads
{
$("#toggle").toggle(function()
{ // first click hides login form, shows password recovery
$("#login-form").hide();
$("#recover-password").show();
},
function()
{ // next click shows login form, hides password recovery
$("#login-form").show();
$("#recover-password").hide();
});
});
Alternately, you can take advantage of jQuery's toggle()
effect to simplify the code (as CMS points out):
$(function() // run after page loads
{
$("#toggle").click(function()
{
// hides matched elements if shown, shows if hidden
$("#login-form, #recover-password").toggle();
});
});