When users click the like button on my site, I want to call a Javascript function.
The source code for the button is:
<div class="fb-like"
data-href="http://www.example.com"
data-layout="button"
data-action="like"
data-size="large">
</div>
In the browser, that renders to:
<div class="fb-like fb_iframe_widget" data-href="http://www.example.com" data-layout="button" data-action="like" data-size="large" fb-xfbml-state="rendered" fb-iframe-plugin-query="action=like&app_id=&container_width=892&href=http%3A%2F%2Fwww.example.com%2Fm%2F174&layout=button&locale=en_US&sdk=joey&size=large"><span style="vertical-align: bottom; width: 63px; height: 28px;"><iframe name="fb56152a7ff1cc" width="1000px" height="1000px" frameborder="0" allowtransparency="true" allowfullscreen="true" scrolling="no" title="fb:like Facebook Social Plugin" src="https://www.facebook.com/v2.5/plugins/like.php?action=like&app_id=&channel=http%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2FfTmIQU3LxvB.js%3Fversion%3D42%23cb%3Dfe277476c6182%26domain%3Dlocalhost%26origin%3Dhttp%253A%252F%252Flocalhost%253A8000%252Ff14aab39703836c%26relation%3Dparent.parent&container_width=892&href=http%3A%2F%2Fwww.example.com%2Fm%2F174&layout=button&locale=en_US&sdk=joey&size=large" style="border: none; visibility: visible; width: 63px; height: 28px;" class=""></iframe></span></div>
I've tried:
$('.fb-like').click(function() {
alert( "Handler for .click() called." );
});
But it doesn't work. I'm wondering if Facebook has some special protection that I don't know about, for editing their buttons?
Uncaught TypeError: $(...).onClick is not a function(…)