Skip to content

Instantly share code, notes, and snippets.

@kier0
Created July 18, 2015 19:56
Show Gist options
  • Select an option

  • Save kier0/5d6578113745a2f36436 to your computer and use it in GitHub Desktop.

Select an option

Save kier0/5d6578113745a2f36436 to your computer and use it in GitHub Desktop.
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>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment