How to add rel attribute based on href filename
<p>I have an ASP search script that returns results mainly of PDFs and some other documents. In the bulk of the site I use a jQuery plugin called clueTip (by Karl Swedberg) that creates a tooltip when the user hovers over certain links. The content of these links is pulled by ajax from an html file defined in the rel attribute of the link:</p>

<pre><code>&lt;a href="../../example.pdf" class="tips" rel="../../tooltips/example.html&gt;
</code></pre>

<p>When a user does a search I want to be able to dynamically add these tooltips to PDFs from one certain location - <code>../../technicalarticles</code>. So I need to:</p>

<ol>
<li>Find any returned PDFs that are in <code>../../technicalarticles</code> and add <code>class="tips"</code> to the link</li>
<li>From those PDFs I need to extract the relevant file name (everything from the last <code>/</code> to the file extension)</li>
<li>Append that file name to the <code>rel</code> attribute</li>
</ol>

<p>Below is my jQuery code so far:</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(".results a").each(function() {
    if (window.location.href.indexOf("technicalarticles") &gt;= 0)
    // if statement to find the right pdfs
    { 
        var firstpos = location.href.lastIndexOf('/')+1; // finds the position of the last / and adds 1
        var lastpos = location.href.lastIndexOf('.')-1; // finds the position of the last . and subtracts 1
        var filename = location.href.substr(firstpos, lastpos); // filename should now have eveything from the last / to the file extension

        $(this).attr('rel', ".data/tooltips/" + filename + ".html"); // adds the rel string to the link
        $(this).addClass('tips'); // adds the class 'tips' to the link
    }
} );
&lt;/script&gt; 
</code></pre>
