jQuery to make the first occurrence of a hyperlink bold

The following jQuery will make the first occurrence of a hyperlink (only under blockquotes in this particular case) bold.

<script type="text/javascript"><!--//--><![CDATA[//><!--
jQuery(function($) {
  var aCache = {};
  $("blockquote a[href]").each(function(){
     if ( aCache[$(this).attr("href")] == true ) return;
     aCache[$(this).attr("href")] = true;
//--><!]]> </script>

A technique that is used to nice effect in some magazines is to apply boldface to a new term but only the first time it appears in an article. It helps skim pages and lets you know immediately what the next couple of paragraphs concern. Here is the same idea with links. In this case, only the href attribute is checked so it doesn’t matter if the link text is different, only the first will get the conversion.

DBIx::Class, aka DBIC, is just great. Why DBIx::Class saved me $10 and rescued my kittens so they could grow and learn to love DBIx::Class as I. Do.

Note, it would be a snap to extend this using custom markup with span tags with classes, or perhaps <dfn/> tags so that you could apply it to any term, any way you wish. Though a bit of effort if you don’t already have a publishing/CMS infrastructure that supports the sort of term tagging needed. Not so much to do manually. Of course you could automate most of it with Perl…

digg stumbleupon del.icio.us reddit Fark Technorati Faves