Is it possible to select only part of a string using jquery? For example I have a text
<p>Metuentes igitur idem latrones Lycaoniam magna parte campestrem</p>
So now if the user search for a string, I want it to be highlighted (we use a bold tag for example)
<p>Metuentes igitur idem latrones <b>Lycaoniam</b> magna parte campestrem</p>
And then we can revert back to original string if needed.
- The first question is whether we can select a substring like this using jQuery, and use jQuery method such as
.css()
to apply style to that element. - The second question is if we don't have such selector, how can we achieve it using jQuery or javascript through string manipulation
Thanks.
UPDATED
Thank for everyone effort. Here is a small program, final result of what I'm looking for http://jsfiddle.net/TPg9p/3/ Cheers!