/ Published in: jQuery

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var grammar = { BracedTextRegex : new RegExp('\{.*\}') }; $('td.kanji').linkBracedText(); $.fn.linkBracedText = function() { this.each(function() { // get text in curly-braces, abort if nothing var sentence = $(this).text(); var $bracedText = sentence.match(grammar.BracedTextRegex); if ($bracedText === null) return; var bracedText = $bracedText[0].substr(1,$bracedText[0].length-2); // replace curly-braced text with a span, which serves as an insertion point sentence = sentence.replace(grammar.BracedTextRegex,'<span></span>'); // find the 1st link (magically the 1 I need), change text to what was in curly braces var link = $(this).closest('tr').find('a:first').clone(); link.text(bracedText); //overwrite this element with a copy that has curly-braced replaced with appropriate link $(this).html(sentence).find('span').append(link); })};
Comments
