I am currently working with a JQuery function that highlights a specific word and scrolls to it:
$('article.node--article p, .video-title').highlightWordAndScroll({
words : search_word,
tag : '<span class="found_keyword">',
closingtag : '</span>',
}, scrollTo);
This function wraps the search_word
in a found_keyword
class. However, there is an issue when the word appears within an <img>
tag between some <p>
tags. This causes the image not to render properly.
<p class="rtecenter">
<img alt="" src="/sites/default/files/userfiles/logo_<span class=" found_keyword"="">foto.jpg" style="height:87px; width:332px">
</p>
As a result, the image-rendering breaks. Is there a way to exclude the image tag from the JQuery selector?
EDIT
I have attempted the following code to exclude the image tag, but unfortunately, it did not work...
$('article.node--article p, .video-title').children().not("img").highlightWordAndScroll({
words : search_word,
tag : '<span class="found_keyword">',
closingtag : '</span>',
}, scrollTo);