-1

I was expecting the FBLogin onclick to run the below query, but noting is happening. What have I missed which means this isn't working as expected?

I believe this is an issue with my onlick event and not the function itself.

<a href="#" onclick="FBLogin();" 
role="button" class="btn btn-successFbLi btn-lg fa fa-facebook"</i> 
Sign in with Facebook</a></button><br>

Function

function FBLogin() {
//Fb app information//

window.fbAsyncInit = function() {
    Parse.FacebookUtils.init({
      appId      : 'xxxxxxxxx',
      xfbml      : true,
      version    : 'v2.3'
    });

//rest of function here etc//


}
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Dano007
  • 1,872
  • 6
  • 29
  • 63

1 Answers1

0

Error in the code you provided.

  • wrong anchor tag
  • extra closing tags (<i>, <button>)

The major changes I made in the code:

  • removed onclick attribute
  • added event listener in javascript

Here is the fiddle

Here is the snippet.

function FBLogin() {
  //Fb app information//
  alert("WORKING");
  window.fbAsyncInit = function() {
    Parse.FacebookUtils.init({
      appId: 'xxxxxxxxx',
      xfbml: true,
      version: 'v2.3'
    });

    //rest of function here etc//


  }
}

document.getElementById('login').addEventListener("click", FBLogin);
<a id='login' href="#" role="button" class="btn btn-successFbLi btn-lg fa fa-facebook">
Sign in with Facebook</a>

More about Event Listeners here

Shrinivas Shukla
  • 4,325
  • 2
  • 21
  • 33
  • Care to explain why the inline event handler does not work? – Felix Kling Jul 05 '15 at 09:26
  • using inline event handlers should be avoided. Source : http://stackoverflow.com/a/17378538/4338417. I stopped using inline event handlers after reading this answer. – Shrinivas Shukla Jul 05 '15 at 09:49
  • It's true that they should be avoided, but they are not the source of all problems. You said the OP **needs** to change it, but I don't see why. Blindly changing things hoping it will fix an issue is not a reasonable approach. As you can see, your fiddle works fine with inline event handlers as well: http://jsfiddle.net/6hgk4q32/. So there is certainly no *need* to change this. – Felix Kling Jul 05 '15 at 13:14
  • I changed the statement in my answer. I agree that the code should not be changed blindly. Its just that when I made changes to OP's code, I used `addEventListener` approach as it makes the code a little better. – Shrinivas Shukla Jul 05 '15 at 13:20