find specific text and bold or change
find specific text and bold or change with the class/id help
by 8ogdan
HTML
<head>
<title>Retrolime</title>
</head>
<body>
<p>The world is big and red.</p>
</body>
CSS
#color {
color: red;
}
JavaScript
$.fn.wrapInTag = function(opts) {
var tag = opts.tag || 'strong',
words = opts.words || [],
regex = RegExp(words.join('|'), 'gi'),
replacement = '<'+ tag +'>$&</'+ tag +'>';
return this.html(function() {
return $(this).html().replace(regex, replacement);
});
};
$('p').wrapInTag({
tag: 'em id="color"',
words: ['world', 'red']
});
$('p').wrapInTag({
tag: 'strong',
words: ['is']
});