jQuery Code Snippet to get the alt tags of each image and set the title tag so it is the same as the alt tag. Could be useful to improve SEO for the web page and added support for browsers such as Firefox that utilise image title tags.

jQuery(document).ready(function($) {
	$("img:not([title])").each(function() {
			if($(this).attr("alt") != '') $(this).parent().attr("title", $(this).attr("alt"))
			else $(this).parent().attr("title", $(this).attr("src"));
Tags: jquery get image alt tag, jquery img alt, jquery img title, jquery set image title
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

No Reader comments

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.