I've used regular expression(regex) in javascript
as follows:
function chnColor(){
var str=document.getElementById("myelement").innerHTML;
str=str.replace(/(%)(.*)(%)/g,"<font color='red'>$2</font>");
//Here $2 Means Anything in between % and % This is what you need to color
document.getElementById("myelement").innerHTML=str;
}
DEMO
Hope it helps! cheers :)!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…