I'm trying to create and manipulate the Pin It button after page load. When i change the button properties with js, it should be rerendered to get the functionality of pinning dynamically loaded images. So, does Pinterest have any method like Facebook's B.XFBML.parse() function?
Thanks...
The official way to do this is by setting the "data-pin-build" attribute when loading the script:
Then you can render your buttons dynamically like so:
There is also another method on this site which lets you render them in JavaScript without the script tag.
I built on Derrek's solution (and fixed undeclared variable issue) to make it possible to dynamically load the pinterest button, so it can't possibly slow down load times. Only tangentially related to the original question but I thought I'd share anyway.
at end of document:
in document ready function:
in your document where you want the pinterest button to appear, just add an element with the id pinterestOption, i.e.
hope that helps someone!
this works fine for me: http://www.mediadevelopment.no/projects/pinit/ It picks up all data on click event
The best way to do this:
Realod their script - i.e. using jQuery:
Here's what I did.
First I looked at pinit.js, and determined that it replaces specially-marked anchor tags with IFRAMEs. I figured that I could write javascript logic to get the hostname used by the src attribute on the generated iframes.
So, I inserted markup according to the normal recommendations by pinterest, but I put the anchor tag into an invisible div.
Then, immediately after that, I inserted a script to slurp up the hostname for the pinterest CDN, from the injected iframe.
Then,
And then use it from jQuery like this:
I rewrote the Pinterest button code to support the parsing of Pinterest tags after loading AJAX content, similar to FB.XFBML.parse() or gapi.plusone.go(). As a bonus, an alternate JavaScript file in the project supports an HTML5-valid syntax.
Check out the PinterestPlus project at GitHub.