Facebook connect javascript problem

I added a custom facebook icon to my site. What I want to do is when user press on the facebook icon the facebook connect script should be triggered. I added these two scripts to the <head> of my site:

&lt;script type="text/javascript"&gt;

     window.fbAsyncInit = function() {
   FB.init({appId: '119245164837280', status: true, cookie: true,
             xfbml: true});

 FB.getLoginStatus(function (response) {
 if (response.session) {
  //Do something,User is logged in.
 }
 else {

 }
 });
  FB.Event.subscribe('auth.login', function (response) {    
// When login process completes this event is called.
  Var userid=response.session.uid; // user id of logged in user
 Var accesstoken=response.session.access_token;// access token

});
  FB.Event.subscribe('auth.logout', function (response) {
 //User is loggin out.
});


 });

  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
   &lt;/script&gt;
   
   
&lt;script type="text/javascript"&gt;

FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
       FB.logout(function(response) {
         console.log('Logged out.');
       });
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email'});

&lt;/script&gt;

Also i added <div id="fb-root"></div> right after <body <?php body_class(); ?>>, but when I load my site I keep getting these error messages: document.getElementById(“fb-root”) is null and FB is not defined [Break On This Error] FB.login(function(response) { .

my html:

&lt;a id="facebookiconid"  onclick="FB.login()"&gt;Login&lt;/a&gt;

It sounds liek you need to load some kind of facebook code library, so that the page knows how to handle those FB objects.

The facebook for websites page should be of some help, possibly around the [url=“http://developers.facebook.com/docs/guides/web/#login”]authentication section of the page.