JSFiddle - React, Tailwind, and code Playground
HTML
<div id="example1">
<p>さまざまなWebサイトで<strong>jQueryが活躍</strong>しています</p>
<p>jQuery UIはjQueryに<strong>ウィジェット</strong>などを拡張するプラグインです</strong></p>
</div>
<div id="example2">
<p>さまざまなWebサイトで<strong>jQueryが活躍</strong>しています</p>
<p>jQuery UIはjQueryに<strong>ウィジェット</strong>などを拡張するプラグインです</strong></p>
</div>
CSS
span.highlight {
background-color : #ffa;
color : red;
text-decoration : underline;
}
JavaScript
$(function() {
$('#example1 p').each(function() {
const html = $(this)
.html()
.replace(
/(jQuery(\sUI)?)/g,
'<span class=\"highlight\">$1</span><span style="color:white; background-color:black">$2</span>'
);
$(this).html(html);
});
});
$(function() {
$('#example2 p').each(function() {
const html = $(this)
.html()
.replace(
/(jQuery(?:\sUI)?)/g,
'<span class=\"highlight\">$1</span><span style="color:white; background-color:black">$2</span>'
);
$(this).html(html);
});
});