Show Pinterest hover buttons only on images with specified class

css, html, javascript, jquery, pinterest

Solution

So, one way of doing it in jQuery would be to set all images, by default, to have the attribute:

data-pin-no-hover="true"

The jQuery for this would simply be:

 $("img").attr("data-pin-no-hover", true);

Then below that you could have an additional line changing the value to false for the specific class you want to remove the attribute:

$(".pinit_img").removeAttr("data-pin-no-hover");

Problem

A client wants to have pinit buttons on hover over certain images on the site. I looked at the documentation on Pinterest's site and could only find how to set all images to pinit ones, with the option to turn off some images with a CSS class. But that would mean that 95% of all the images on the site would have to have a nopin class. Is there a way I can apply a class to images like "pinthis" so that ONLY them ones have the pinit buttons attached. I noticed that you can do something like this on Wordpress but this is a custom built site. Thanks in advance! Edit: This is the code I have put in the header tags as described in the Pinterest developer link above: ``` <script type="text/javascript" src="//assets.pinterest.com/js/pinit.js" data-pin-hover="true"></script> ``` This basically sets all images on the page to have pinit buttons, but I need them to only applied to images with a specific class

Original source