Sure you don't want to replace it with a war of text?
innerHTML is indeed the easiest way, but not the best. Try:
Code:
function surroundText(inEl, text, withEl) {
var nv;
for(var i = 0, e = inEl.childNodes; i < e.length; ++i)
if(e[i].nodeType === 3) {
if((nv = e[i].nodeValue).indexOf(text) !== -1) {
var tels = [
nv.substr(nv.indexOf(text) + text.length),
text,
nv.substr(0, nv.indexOf(text))
];
for(var j = 0; j < tels.length; ++j)
inEl.insertBefore(e[i], document.createTextNode(tels[j]));
inEl.parentNode.removeChild(inEl);
return true;
}
} else
if(surroundText(e[i], text, withEl))
return true;
return false;
}
Untested.
Bookmarks