This is close:
var findIt = 'Javascript';
$.expr[":"].containsNoCase = function(el, i, m) {
var search = m[3];
if (!search) return false;
// we'll use text to find what we want...
return eval("/" + search + "/ig").test($(el).text());
};
$("p:containsNoCase('"+ findIt +"')").each(function() {
// and then html when we are ready to replace
var ht = $(this).html();
var pos= ht.indexOf(findIt);
var start = ht.substring(0, pos);
var end = ht.substring(pos+findIt.length);
$(this).html(
start
+'<a href="javascript:alert(\'heartrate.cfm\')">'+findIt+'</a>'+end);
});
But what you are looking for is a tough thing to provide. You want to search only the text of elements, but need to update the HTML content of the element where it was found (in order to add links). When you go back and use html() to update the element, you'll end up potentially replacing things you don't mean to.
For example this is fine:
<p>Hey, Javascript is fun.</p>
Where as this has issues:
<p><img src="something/Javascript.png">Whee, yaa Javascript</p>
The text within the image src is replaced errantly. If there's a way you can find the position of the matching text within an element not surrounded by, or within a tag, it would be possible to replace it cleanly. Of course you can use text(), but then you can't use any HTML in what you are adding back in :(. Maybe I'll check back and see if anyone has anything else to offer.