我有以下 JQuery 函数:
$('article.node--article p, .video-title').highlightWordAndScroll({
words : search_word,
tag : '<span class="found_keyword">',
closingtag : '</span>',
}, scrollTo);
它基本上包装了一个类 found_keyword
search_word
周围.而已。
但在一些<p>
之间标签是 <img>
标签。而且因为 found_keyword
类包裹在图像名称周围,图像不再正确呈现。
<p class="rtecenter">
<img alt="" src="/sites/default/files/userfiles/logo_<span class=" found_keyword"="">foto.jpg" style="height:87px; width:332px">
</p>
因此,图像渲染被破坏了。有没有办法在 JQuery 选择器中排除图像标签?
编辑
感谢您的链接。我试过以下代码,但没有运气......
$('article.node--article p, .video-title').children().not("img").highlightWordAndScroll({
words : search_word,
tag : '<span class="found_keyword">',
closingtag : '</span>',
}, scrollTo);
最佳答案
你为什么不做更多的 Jquery 来删除之后的类,但只针对 img 标签
关于javascript - 具有选择器和非选择器的 JQuery 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23203540/