addThis share not working for ajax loaded sharing icons

addThis is a robust solution for sharing content to different social platforms. It has plugins also which can be used for this purpose. addThis provides the html or we say toolbox which shows the social icons when we implement that to any page or post. We can also provide the url, title media or description of the page or post within the toolbox which are to be shared through social media icons.

Sometimes, we need to show this toolbox with sharing content through ajax. I we simply show the toolbox html through ajax, then the sharing icon will not display or will not work. To show and to make them work, we will have to reinitialize the toolbox in just single line which is :

addthis.toolbox(‘.addthis_toolbox’);  // Here ‘.addthis_toolbox’ is the the class applied on the toolbox html

Here is an example of showing addthis social icons through ajax request and reinitialize them :

jQuery.ajax({
type: ‘post’,
url: ajax_url,
data: data,
dataType: ‘json’,
success: function(response) {
jQuery(‘#sharing_div’).html(response); // response includes the html of addthis sharing icons
addthis.toolbox(‘.addthis_toolbox’);
}
});

Thus, we can simply reinitialize the addthis sharing toolbox in javascript.

Leave a Reply