Progressive enhancement with jQuery
I’ve been having a lot of fun with jQuery recently. One of the things particularly easy to do with it is write nice and unobtrusive javascript (a good start when looking at progressive enhancement). This is largely down to the fact that it’s very easy to find particular elements within the DOM - with any level of specificity - and attach behaviour to them.
On the site I’ve been building at work, one particular example was to get jQuery to write in the “Print page” link, since that needs javascript.
// add print page link - since it can only work for JS, only add it for JS users
$('<li></li>') // create list item
.addClass('print') //add relevant class to it
.append('<a href="javascript:window.print();">Print this page</a>') //put in the link
.insertBefore('li a.foo'); //add before the li item with link of class 'foo'
The above example is slightly more verbose than it need be, but it illustrates some of the different built-in functionalities of jQuery quite well.
Continue reading Progressive enhancement with jQuery