jQuery Google Image Plugin

Here is a quick and convenient Google Image plugin for jQuery. Just give it an IMG tag with an empty src or a default image. It will use the alt text of your image, and select the first image based on that term.

$.fn.googleImage = function() {
		return $(this).each(function() {
			var self = this;
			var url = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=2&start=1&callback=?&q=" + $(this).attr("alt");
			$.getJSON(url, function(data) {
				if(data.responseData.results.length > 0)
					$(self).attr("src", data.responseData.results[0].unescapedUrl);
				else
					$(self).attr("src","");
			});
		})
	}
About these ads

3 Responses to jQuery Google Image Plugin

  1. Manoj Nair says:

    Really nice… thanks!

  2. fasdf says:

    hfjghj

  3. Larry Battle says:

    Awesome plugin!
    You saved me so much time.

    bateru.com/news

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: