Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Created January 24, 2012 22:09
Show Gist options
  • Save tncbbthositg/1673028 to your computer and use it in GitHub Desktop.
Save tncbbthositg/1673028 to your computer and use it in GitHub Desktop.
// basic example
$('span').filter(function() {
return this.innerHTML.match(/\b(fire|aqua|elec|wood)\b/gi);
}).css("border", "1px solid red");
// styling each individual word
var fire = "<span style='border: 3px solid red;'>fire</span>";
var aqua = "<span style='border: 3px solid blue;'>aqua</span>";
var elec = "<span style='border: 3px solid gray;'>elec</span>";
var wood = "<span style='border: 3px solid brown;'>wood</span>";
$('span').filter(function() {
return this.innerHTML.match(/\b(fire|aqua|elec|wood)\b/gi);
}).each(function(i, o) {
o.innerHTML = o.innerHTML.replace("fire", fire)
.replace("aqua", aqua)
.replace("elec", elec)
.replace("wood", wood);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment