/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var term = 'Valves'; var value = 'Foo Foo Valves Blah Yo Yo'; var regex = new RegExp(term,'ig'); var replaced = value.replace(regex,'<span>$&</span>'); alert(replaced); //Foo Foo <span>Valves</span> Blah Yo Yo