It seems Jonathan Palardy doesn’t like my old prev/next bookmarklets. He thinks I should actually include code that works, even if it means having people pull some javascript library from my site. So do I.

Trouble is, I don’t use those anymore. It’s a real hassle to negotiate Prototype to play nice with everyone else’s javascript, so I’ve moved onto a simpler approach. Like Mr. Palardy, I wanted something using something standard and with builtin support from modern browsers. But I thought I’d give CSS selectors a shot using the Selectors API, available in Firefox 3.1+, IE8, Safari 3.1+, and Opera 10.

What we want is very simple: elements with a rel value of prev or next. You find those easily with the CSS selectors [rel~=prev] or [rel~=next]. We need to get the link those elements are pointing to, so we just pull that from the href attribute. Finally, we tell the browser to update the document location with that URI. Like so:

location = document.querySelector('[rel~=prev]').getAttribute('href');

Of course, I took a second to wrap this stuff up as proper bookmarklets. Just drag these to your link bar: prev and next.