I have this html:
<div id="signbtn">
<a id="login-link" class="btnsignin" title="Login">Sign in</a>
</div>
Upon successful log in, I am able to change the anchor class to “btnsignout” and the title to “Sign out”. So far so good. And now when I click on the anchor to sign out, the log out page loads into content div, but the anchor title doesn’t change back to “Sign in”. Clicking on it doesn’t do anything. The anchor is dead.
Can someone take a look and let me know what change I need to make to the jquery function. Thanks for all the help!
Here is my jquery code:
$('#signbtn').click(function() {
$.each($(this).children('a'), function(){
if($(this).hasClass('btnsignout')){
$('#signbtn a').attr('name', 'Sign In');
$(this).removeClass('btnsignout');
$(this).addClass('btnsignin');
$("#content").load("../admin/logout.php");
}
})
return false;
});
Here’s an example of how I would do this.
Using “live” makes it easier I think, and this way you can have more than one button in your doc and it would work (some changes would be needed to change all buttons from login to logout, and not only the clicked button).
Declaring the events functions separately also makes it easier to understand (I think).
Maybe you could make a jQuery plugin of this. This way it would be really easier to apply it on an HTML doc, and you could regroup all functions about signing in and out in this plugin.
Here’s an example plugin (I didn’t exec this code, there’s probably bugs) :
Sorry I had some time to kill 🙂
Nico