Using jQuery to highlight a character of a string on a webpage

前端 未结 4 1803
眼角桃花
眼角桃花 2021-01-27 05:35

I want to use jQuery to highlight a character of a string on a webpage at an index of some value. The value is variable – one time it will be at the index of 2, and the ne

4条回答
  •  星月不相逢
    2021-01-27 06:05

    You can do this with HTML and CSS.

    Then highlight it dynamically with CSS classes and Jquery.

    $("#textholder").html("Here is some Highted text");
    

    Then your CSS could be:

    .highlight {
       display:inline-block;
       background-color:"yellow";
    }
    

    https://jsfiddle.net/aaronfranco/x3h4qnxj/1/

提交回复
热议问题