Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You didn't posted what you have. I think this is what you are mentioning.</p> <p>Check this. I can do this for you but you have to do it in your ideas</p> <pre><code>function highlightInElement(elementId, text){ var elementHtml = document.getElementById(elementId).innerHTML; var tags = []; var tagLocations= []; var htmlTagRegEx = /&lt;{1}\/{0,1}\w+&gt;{1}/; //Strip the tags from the elementHtml and keep track of them var htmlTag; while(htmlTag = elementHtml.match(htmlTagRegEx)){ tagLocations[tagLocations.length] = elementHtml.search(htmlTagRegEx); tags[tags.length] = htmlTag; elementHtml = elementHtml.replace(htmlTag, ''); } //Search for the text in the stripped html var textLocation = elementHtml.search(text); if(textLocation){ //Add the highlight var highlightHTMLStart = '&lt;span class="highlight"&gt;'; var highlightHTMLEnd = '&lt;/span&gt;'; elementHtml = elementHtml.replace(text, highlightHTMLStart + text + highlightHTMLEnd); //plug back in the HTML tags var textEndLocation = textLocation + text.length; for(i=tagLocations.length-1; i&gt;=0; i--){ var location = tagLocations[i]; if(location &gt; textEndLocation){ location += highlightHTMLStart.length + highlightHTMLEnd.length; } else if(location &gt; textLocation){ location += highlightHTMLStart.length; } elementHtml = elementHtml.substring(0,location) + tags[i] + elementHtml.substring(location); } } //Update the html of the element document.getElementById(elementId).innerHTML = elementHtml; } highlightInElement("fatDoggie","The dog is really really fat"); </code></pre> <p>This fiddle was made to highlight a set of text instead you should get the variable in search and place in the <code>highlightInElement("Element","Var");</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload