简体   繁体   English

带有选择器和非选择器的jQuery选择器

[英]JQuery selector with both a selector and not-selector

I have following JQuery function: 我有以下JQuery函数:

$('article.node--article p, .video-title').highlightWordAndScroll({
    words       : search_word,
    tag         : '<span class="found_keyword">',
    closingtag  : '</span>',
}, scrollTo);

which basically wraps a class found_keyword around the search_word . 基本上包装类found_keyword围绕search_word Nothing more. 而已。 But between some <p> tags are <img> tags. 但是在<p>标记之间是<img>标记。 And because the found_keyword class is wrapped around the image name, the image isn't rendered properly anymore. 并且由于found_keyword类被包装在图像名称周围,因此该图像不再正确呈现。

<p class="rtecenter">
   <img alt="" src="/sites/default/files/userfiles/logo_&lt;span class=" found_keyword"="">foto.jpg" style="height:87px; width:332px"&gt;
</p>

And so, the image-rendering is broken. 因此,图像渲染被破坏了。 Is there a way to exclude the image tag in the JQuery selector? 有没有办法在JQuery选择器中排除image标签?

EDIT 编辑
Thanks for the link. 感谢您的链接。 I've tried with following code, but no luck there... 我已经尝试使用以下代码,但是没有运气...

$('article.node--article p, .video-title').children().not("img").highlightWordAndScroll({
    words       : search_word,
    tag         : '<span class="found_keyword">',
    closingtag  : '</span>',
}, scrollTo);

您为什么不做更多的Jquery来删除之后的类,但是仅用于img标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM