I was just playing with Facebook and Twitter Like & Tweet Button respectively. When I noticed that dynamically appended Twitter button does not work but manually added Anchor works. Why is it so?
Here’s The Fiddle : Fiddle
You can see it is not working.
Code:
$("body").append('<a href="https://twitter.com/share" class="twitter-share-button" data-dnt="true" data-count="none" data-via="SitesTwitter">Tweet</a>');
How interesting. The current code it’s actually works for me on: http://codepen.io/anon/pen/punfx but I got the same issue of you on your Fiddle.
I think it’s a timing issue. You have to inject the
twitter-wjsonce you added dynamically your button. I believe this script will probably scan the page to modifying any link that has thetwitter-share-buttonclass, or something like that. So if you add the button after the execution of that script, your link won’t be scanned.