0

I Have written a method to highlight the matching words in the large file using TinyMce 4.7 version plugin.

Expected: To highlight the matching word and cursor to next to that similar like MS Word.

Issue: By the below method only for the first instance is highlighting and all the remaining are not highlighting.

Ex: if I search a word like chapter which is present in page 1, 4,6,7,8,9... now only the page 1 matching word is showing in yellow colour. In the same page if we have the word more than 1 time even after it is not showing.

 function customhighlight(searchWord) {
              //  debugger;               
                var searchvalue = searchWord;
                var str2 = '';
                var insensitiveStr = searchvalue.toLowerCase();
                var strnew = '';
                var strTo = "<span style='background-color:Yellow; font-weight:bold;' ><b>" + searchvalue + "</b></span>";
               
                    str2 = $("#editor_ifr").contents()[0].documentElement.childNodes[1].innerHTML.replace(searchvalue, strTo, "gi");
                
                $("#editor_ifr").contents()[0].documentElement.childNodes[1].innerHTML = str2;
            }
  • Welcome to Stack Overflow. Please provide a Minimal, Reproducible Example: https://stackoverflow.com/help/minimal-reproducible-example – Twisty Dec 16 '20 at 20:01
  • This might also be related: https://stackoverflow.com/questions/40558384/how-to-highlight-sentences-in-tinymce-like-this – Twisty Dec 16 '20 at 20:03
  • This might also help: https://stackoverflow.com/questions/52976156/highlight-text-with-tinymce – Twisty Dec 16 '20 at 20:04

0 Answers0