kier0
7/18/2015 - 7:56 PM

Wrap a certain character in a line of text in a span - to isolate and style. Example below is finding all the "i, I and ." in the text. *

Wrap a certain character in a line of text in a span - to isolate and style. Example below is finding all the "i, I and ." in the text.

****NOTE**** Wordpress REMOVES backslashes needed to make a period read as a period and not a "wildcard". Must load this code in an external js file.

jQuery(document).ready(function() {
jQuery(".content-title p:contains('i')").html(function(_, html) {
   return  html.replace(/(i)/g, '<span class="pink">$1</span>');
});


// Pink I's 
jQuery(".content-title p:contains('I')").html(function(_, html) {
   return  html.replace(/(I)/g, '<span class="pink">$1</span>');
});
// Pink periods 
jQuery(".content-title p:contains('\.')").html(function(_, html) {
   return  html.replace(/(\.)/g, '<span class="pink">.</span>');
});
});