Is it possible to select only part of a string using jquery? For example I have a text
Metuentes igitur idem latrones Lycaoniam magna parte campestrem&l
Do you know when the HTML is created which word you want? Then I would suggest doing the following instead
Metuentes igitur idem latrones Lycaoniam magna parte campestrem
`
now if you wanna highlight it just do
$(".js-highlightable").toggleClass("highlighted");
Any styles can be defined in the highligthed
class. You could also use an id
for the span instead if you want to be able to apply the change to only that single element and not all elements with js-highlightable
class.