Change all instances of a word AND update the color of ONLY the changed words with jQuery. Here's what I have at the moment:
if($("body").html($("body").html().replace(/Copyright © \d{4}\b/g,"Copyright ©
2018"))){
$(this).css({"color": "red"});
}
I'm sure there's a simple solution and my jquery isn't the best at the moment. I tried adding a class to it and then using the class selector to change it, but I didn't know what to attach the class selector to. So to be clear...
I'm looking for all instances of "Copyright © [1234]" and updating it to the current year and then I want to change the color of those specific instances to red.
Thanks.
If the text is inside an element like
<p>or<h1>and you can not wrap the match in for example a<span>you could use this example. Note that whenCopyright © 2011is placed directly inside the<body>tag, the<body>tag will get color red.Using test without anchors will return true if it can find a match in the string. If you want an exact match you could use anchors
^$to assert the start and the end.^Copyright © \d{4}$If there can be whitespace characters at the start or at the end you could
\s*:^\s*Copyright © \d{4}\s*$