Sep 4th 2010 09:12 am

Using jQuery during regular browsing

Recently I’d found myself working to make some pages 508 compliant. One rule of 508 compliance is that all images must have alt tags to describe them to visually impaired users. My task was to go through a list of pages and add all the missing alt tags.

Using a javascript library like jQuery or prototype this task becomes much easier. Simply open up a javascript console in Internet Explorer Developer Toolbar or firebug and query the page with something like:

>
$("a").filter(function(){return this.alt == "";}).map(function() {return this.href;})

Unfortunately, many of these pages were legacy pages without any reference to a javascript library. An easy workaround to this was to dynanmically add a reference to the library (jQuery in my case) using a content delivery network. The Microsoft Ajax Content Delivery Network provides such a copy of jQuery that’s free and accessible from anywhere.

var script = document.createElement('script');
script.setAttribute('src', "http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js")
document.links[0].appendChild(script)

The more I used it, the more I found a need to query the page for links and images. For me it’s been a handy script to keep around, particularly when gleaning data from rss feeds.

No Comments yet »

Trackback URI | Comments RSS

Leave a Reply

« | »