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

时间:2014-04-21 18:35:42

标签: javascript jquery html css

我有以下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_&lt;span class=" found_keyword"="">foto.jpg" style="height:87px; width:332px"&gt;
</p>

因此,图像渲染被破坏了。有没有办法在JQuery选择器中排除图像标记?

修改
谢谢你的链接。我尝试过以下代码,但没有运气......

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

1 个答案:

答案 0 :(得分:0)

为什么你不再做Jquery以后删除类,但仅限img标签

相关问题