If you want to perform a simple string replacement, the following will do:
var div = document.getElementById("t1");
div.innerHTML = div.innerHTML.replace(/g/g, "<a href='http://www.google.com'>g</a>");
If you need more dynamics, e.g. substituting a word with a link, depending on the value, use:
Example: Replace g or G with different URLs:
var div = document.getElementById("t1");
var mapper = {
g: "http://www.google.com",
G: "http://stackoverflow.com"
};
div.innerHTML = div.innerHTML.replace(/[Gg]/g, function(fullmatch){
return "<a href='" + mapper[fullmatch] + "'>" + fullmatch + "</a>";
});