Highlight specific lines in a given long line in javascript

I have a long line and a list of other lines that I need to mark in a long line. Let's say we have abcdefghijk, and the lines that I need to note are ghiand abc.

What is the easiest way to do this in Javascript and CSS? I was thinking about using a method exec()that will return the starting index of a string in a long string.

Then I will have the starting index and row size. So, I could find him in a long chain. How can I highlight it? Perhaps using CSS?

+5
source share
2 answers

jQuery . ...

?

1 -

jquery.highlight-3.js (2 ) jQuery.

2 -

CSS:

.highlight { background-color: yellow }

3 - /

. "ghi" ( ), , :

$('form').highlight('ghi');

4 -

removeHighlight. ID- .

$('#highlight-plugin').removeHighlight();
+1

, , span. , HTML :

<span class="highlight">abc</span>def<span class="highlight">ghi</span>jk

CSS:

.highlight
{
    background-color:yellow; 
}
0

All Articles