<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>610 Design &#187; accessibility</title>
	<atom:link href="http://www.610design.com/tag/accessibility/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.610design.com</link>
	<description>Design the code</description>
	<lastBuildDate>Tue, 08 Feb 2011 12:57:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>alt to the title to the title to the alt</title>
		<link>http://www.610design.com/coding/alt-to-the-title-to-the-title-to-the-alt/</link>
		<comments>http://www.610design.com/coding/alt-to-the-title-to-the-title-to-the-alt/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 16:37:17 +0000</pubDate>
		<dc:creator>schoey</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.610design.com/?p=136</guid>
		<description><![CDATA[The alt tag and the title tag are the unsung heros of accessablity for images. Years ago a design/developer would have to manually write the alt text and title tag for every image and 9 times out of 10 the text would be the same. Now-a-days the process has become much easier with the use [...]]]></description>
			<content:encoded><![CDATA[<p>The alt tag and the title tag are the unsung heros of accessablity for images. Years ago a design/developer would have to manually write the <code>alt</code> text and <code>title</code> tag for every image and 9 times out of 10 the text would be the same. Now-a-days the process has become much easier with the use of jQuery.</p>
<p>Let&#8217;s say for example, you are a designer that&#8217;s in the good habbit of using always using alt text with your images but you want to duplicate the text in the <code>title</code> attribute. Now, if you were really up for the task you could go through every page and manual insert the <code>title</code> and copy the text from the <code>alt</code> attribute and paste it inside the quotes of the <code>title</code> tag. Needless to say, this would not only be a rediculously time consuming way of implemeting this change but an absolutly not an efficient way of doing things. Well, as fortune would have it you write a few lines of jQuery to and achieve</p>
<h3>jQuery breakdown</h3>
<p>This script inserts the alt text into the title text or the title text into the alt text and if for some reason you are a &#8220;lazy&#8221; designer/developer and didn&#8217;t insert an alt text or a title text it will take the url for the source file and insert that into the title attribute.</p>
<p>Okay, let&#8217;s say I&#8217;ve got 4 images. The first has an <code>alt</code> attribute, but no <code>title</code>. The second has both an <code>alt</code> and a <code>title</code>. The third is just a copy of the first. The last has no <code>alt</code> or <code>title</code>.</p>
<pre class="code">&lt;img src="<span class="code-element">images/accept.png</span>" alt="<span class="code-element">Accept</span>" /&gt;&lt;br /&gt;
&lt;img src="<span class="code-element">images/application_error.png</span>" alt="<span class="code-element">Error</span>" <img src="http://www.610design.com/wp-content/uploads/2010/02/nextline.png" alt="word wrap" width="12" height="9" />
title="<span class="code-element">Error</span>" /&gt;&lt;br /&gt;
&lt;img src="<span class="code-element">images/accept.png</span>" alt="<span class="code-element">Accept</span>" /&gt;&lt;br /&gt;
&lt;img src="<span class="code-element">images/application_error.png</span>" /&gt;&lt;br /&gt;
</pre>
<p>I began looking at jQuery selectors to see if it was possible to find all images that were missing a <code>title</code> attribute.<br />
This can be done with the following selector</p>
<pre class="code">img:<span class="code-element">not</span>([title])
</pre>
<p>Reading left to right we have: All img tags <strong>NOT</strong> having title as an attribute.</p>
<p>Now I needed to modify it so that I could set the <code>title</code> attribute to the <code>alt</code> value.</p>
<pre class="code">$("<span class="code-element">img:not([title])</span>").each(<span class="code-green">function</span>() {
 $(<span class="code-green">this</span>).attr("<span class="code-element">title</span>", $(<span class="code-green">this</span>).attr("<span class="code-element">alt</span>"))
})</pre>
<p>This worked like a charm, but obviously, only worked in cases where the <code>alt</code> attribute existed. Many times the filename of the image can give you a clue as to what the image does. I don&#8217;t know about you, but I will often run across web apps that make use of tiny icons (with no title attribute) that leave me scratching their head as to their actual purpose. I modified the code a bit to use the <code>src</code> attribute when <code>alt</code> was empty.</p>
<pre class="code">$("<span class="code-element">img:not([title])</span>").each(<span class="code-green">function</span>() {
 	<span class="code-green">if</span>($(<span class="code-green">this</span>).attr("<span class="code-element">alt</span>") != '') <img src="http://www.610design.com/wp-content/uploads/2010/02/nextline.png" alt="word wrap" width="12" height="9" />
	$(<span class="code-green">this</span>).attr("<span class="code-element">title</span>", $(<span class="code-green">this</span>).attr("<span class="code-element">alt</span>"))
 	<span class="code-green">else</span> $(<span class="code-green">this</span>).attr("<span class="code-element">title</span>", $(this).attr("<span class="code-green">src</span>"))
})</pre>
<p>So in the end the 4 images would render identical alt and title value. If the image didn&#8217;t have an alt or title value it will add the images src to those values.</p>
<pre class="code">&lt;img src="<span class="code-element">accept.png</span>" alt="<span class="code-element">Accept</span>" title="<span class="code-element">Accept</span>" /&gt;&lt;br /&gt;
&lt;img src="<span class="code-element">application_error.png</span>" alt="<span class="code-element">Error</span>" <img src="http://www.610design.com/wp-content/uploads/2010/02/nextline.png" alt="word wrap" width="12" height="9" />
title="<span class="code-element">Error</span>" /&gt;&lt;br /&gt;
&lt;img src="<span class="code-element">accept.png</span>" alt="<span class="code-element">Accept</span>" title="<span class="code-element">Accept</span>" /&gt;&lt;br /&gt;
&lt;img src="<span class="code-element">application_error.png</span>" alt="<span class="code-element">application_error.png</span>" <img src="http://www.610design.com/wp-content/uploads/2010/02/nextline.png" alt="word wrap" width="12" height="9" />
title="<span class="code-element">application_error.png</span>" /&gt;&lt;br /&gt;
</pre>
<p>Live demo on <a href="http://www.nlm.nih.gov/medlineplus/magazine/">MedlinePlus the Magazine</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.610design.com/coding/alt-to-the-title-to-the-title-to-the-alt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

