0

I'm trying to find connective words in a string of text and convert them from uppercase to lower case.

I've managed to get it working using this:

$(".breadlinks:contains('or')").html(function(_, html) {
    return  html.replace(/(or)/g, '<span class="smallcaps">$1</span>')
});

But this will work if the word isn't or but it contains or like order, I only want it to wrap the text in smallcaps class if it exact matches.

Here is a link the the JSFiddle https://jsfiddle.net/zjfrk3nd/16/

WebDevB
  • 492
  • 2
  • 7
  • 25

2 Answers2

0

I think you need to select the whole text from the link and then do a regex for the "or" like here: jQuery replacing "small-caps" - Content is Duplicating HTML between <h3> tags

0

Try this

$(".breadlinks:contains('Or')").each(function() {
    var updatedHtml = $(this).html().replace(/(?:^|\b)(Or)(?=\b|$)/, '<span class="smallcaps">$1</span>');
    $(this).html(updatedHtml);
});
Mukesh Kumar
  • 611
  • 7
  • 17