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;
     $(this).css({fontWeight:"bold"});
  });
});
//--><!]]> </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
Your information (required) Name*
Email*
Website

* Indicates required fields; email is used for validation and is not displayed on the site.

Your comment
Commenting on jQuery to make the first occurrence of a hyperlink bold
Title

Body is limited to ≈1,000 words. Paragraphs—but not line breaks—are automatically inserted. Valid XHTML is required. These are the allowed tags–

<a href=""></a> <br/> <acronym title=""></acronym> <abbr title=""></abbr> <code></code> <pre></pre> <tt></tt> <ins></ins> <del></del> <hr/> <cite></cite> <b></b> <i></i> <sup></sup> <sub></sub> <strong></strong> <em></em> <h1></h1> <h2></h2> <h3></h3> <q></q> <blockquote></blockquote>