Highlight based on text match

by crduling

HTML

<div class='text'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

<div id='matchingHighlight'>
Lorem ipsum <!-- Highlight this text within <div id='text'></div> value !-->
</div>

CSS

.highlight {
    background: #B0B0B0;
}

.highlight:hover {
  background: #C8C8C8;
  cursor: pointer;
}

JavaScript

var $text = $('.text');
    var textToHighlight = $('#matchingHighlight').text().trim();
    var textCurrent = $text.html().trim();
    var isTextExists = textCurrent.indexOf(textToHighlight) > -1;

    if(isTextExists) {
        textCurrent = textCurrent.replace(textToHighlight, "<span class='highlight'>" + textToHighlight + "</span>");
        $text.html(textCurrent);
    }