<p>I'm hand-maintaining an HTML document, and I'm looking for a way to automatically insert a link around text in a table. Let me illustrate:</p>

<pre><code>&lt;table&gt;&lt;tr&gt;&lt;td class="case"&gt;123456&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</code></pre>

<p>I would like to automatically make every text in a TD with class "case" a link to that case in our bug tracking system (which, incidentally, is FogBugz).</p>

<p>So I'd like that "123456" to be changed to a link of this form:</p>

<pre><code>&lt;a href="http://bugs.example.com/fogbugz/default.php?123456"&gt;123456&lt;/a&gt;
</code></pre>

<p>Is that possible? I've played with the :before and :after pseudo-elements, but there doesn't seem to be a way to repeat the case number.</p>

Not in a manner that will work across browsers. You could, however, do that with some relatively trivial Javascript..
```
```
function makeCasesClickable(){
    var cells = document.getElementsByTagName('td')
    for (var i = 0, cell; cell = cells[i]; i++){
        if (cell.className != 'case') continue
        var caseId = cell.innerHTML
        cell.innerHTML = ''
        var link = document.createElement('a')
        link.href = 'http://bugs.example.com/fogbugz/default.php?' + caseId
        link.appendChild(document.createTextNode(caseId))
        cell.appendChild(link)
    }
}
```
```
You can apply it with something like
```
onload = makeCasesClickable
```
, or simply include it right at the end of the page.