Skip to content

How to Add Google Plus 1 Itemprop Attributes to All Images in Dynamically Loading Content With jQuery

by on July 3, 2012

If your content is loading dynamically, you will probably need to use the delay, to give all the images time to be added to the DOM before the script runs. If there is no dynamic content, just use the simple script in your usual jQuery wrapper code.

Simple Script

$(‘img’).attr(‘itemprop’,’image’);

Delayed Script

//delayed setting of img ItemProp on loading blog images
function setImgItemProp (){
    $(‘img’).each(function(index) {
            $(this).attr(‘itemprop’,’image’);
    });
}
    setTimeout(setImgItemProp,1500);

Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: