Skip to content

Instantly share code, notes, and snippets.

@davidrenne
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidrenne/aae2b2e00bcf115ba3cf to your computer and use it in GitHub Desktop.
Save davidrenne/aae2b2e00bcf115ba3cf to your computer and use it in GitHub Desktop.

Share this. If I had the below HTML in my DOM:

<a class="st_sharethis_custom button share-track tiny radius secondary share player-share">Share</a>

and it already gets bound, I cannot easily dynamically set the st_url unless I completely delete this from the DOM. So the below code is the only way I could figure out how to dynamically change URLs in the same button. I tried to unset st_processed. And also had issues using jquery's prop function. It seems somehow you guys will only pick up when the function attr() is called.

This is very frustrating of a work around to try to dynamically create a button! Please make developer experience better by producing some kind of article to swap out url's on the fly.

Thanks!

    $('.share-this-player').html('<a class="st_sharethis_custom button share-track tiny radius secondary share player-share">Share</a>');
    $('.player-share').attr('st_url', $('#full_uri').val() + current_slug_full_url);
    $('.player-share').attr('st_title', 'adsfdsadasf sadf ');
    try {
        if (window.stButtons && window.stLight){
            stButtons.locateElements();
            var switchTo5x = true;
            stLight.options({publisher:'XXXXXXXXX'});
        }
    } catch (e) {  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment