I am trying to activate an alert when I click on Login link, surprisingly nothing happens.
I need some help here.
I want alert to popup when login link is clicked, but surprisingly nothing happens.
thanks,
Mick
<!DOCTYPE html>
<html>
<head>
<title>Facebook Client-side Authentication Example</title>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
// want Alert to popup when I click on auth-loginlink
$("#auth-loginlink").on("click",function () {
alert("hi hello");
});
// ultimately I would like this to be binded with login and logout link
$("#auth-logoutlink").on("click", bindLogout);
function bindLogin(event){
alert("hello");
//FB.login();
};
function bindLogout(event){
alert("Out !!!");
//FB.logout();
};
</script>
<h1>Facebook Client-side Authentication Example</h1>
<div id="auth-status">
<div id="auth-loggedout">
<a href="#" id="auth-loginlink">Login</a>
</div>
<div id="auth-loggedin" style="display:none">
Hi, <span id="auth-displayname"></span>
(<a href="#" id="auth-logoutlink">logout</a>)
</div>
</div>
</body>
</html>
You code is executed before the element are loaded in the page.
That happens because your script is above the element in the HTML.
You will need to either move the script at the bottom of the page or the more robust way to call it once the DOM is ready.
jQuery provides a method for just that.
or the short version of
Documentation at http://api.jquery.com/ready/