substring selector with jquery?

后端 未结 5 1095
南笙
南笙 2021-01-23 01:02

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

5条回答
  •  一向
    一向 (楼主)
    2021-01-23 01:28

    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.

提交回复
热议问题