0

Trying to fire 'onclick' event on a containing div when a user clicks the Twitter "share" button. I'm using twitter's recommended implementation, which is a hyperlink and function. The function replaces HTML on the page and when it does, my 'onclick' won't fire.

<div id="shareTwitter" onclick='alert("onclick!");'>
    <a href="https://twitter.com/share" class="twitter-share-button" data-url="https://www.stackoverflow.com" data-count="none">Tweet</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>

Here's the fiddle: http://jsfiddle.net/tysonkoska/vxzqkL3h/

If you remark out the script, the 'alert' fires fine. Maybe there's a different/better way to to the integration?

Thanks...

user3338114
  • 9
  • 1
  • 4

1 Answers1

1

You can't handle click events on this element, because it's in an iFrame, however twitter gives you the opportunity to bind events to the button.

see fiddle

http://jsfiddle.net/ZwHBf/162/
Shailendra Sharma
  • 6,976
  • 2
  • 28
  • 48