find
returns elements using the specified selector. Since *
will match all elements, it's basically a no-op. What you are trying to do is selecting part of an element. This is not possible. You have to create a specific element arround the asterisk first.
Solution:
You can use a helper method to wrap all *
in a span
with a custom class:
$('.highlight').each(function() {
var regex = new RegExp('\*', 'g');
this.innerHTML = this.innerHTML.replace(regex, '<span class="hilite">*</span>');
}
)
Then you just apply the formatting you want for the hilite
class.
Edit: The code is modified from here Highlight a word with jQuery there are also some more suggestions which might help.
Edit2: added suggestions from comment & explanation above