查找其父级包含一些文本的jquery元素

时间:2014-05-14 07:54:00

标签: javascript jquery

我有以下结构:

<td width="270px">
<img class="bullet" border="0" valign="top" src="gray-bullet.gif">
this is the text
</td>

我需要一个查询来选择带有类子弹的img,其父级包含文本“这是文本”

提前致谢。

2 个答案:

答案 0 :(得分:1)

您可以使用:contains选择器。

  

选择包含指定文本的所有元素。

试试这个:

  $('td:contains("this is the text") img.bullet');

<强> Working Demo

答案 1 :(得分:0)

尝试使用过滤器:

$('td').filter(function(){
    return $(':contains(this is the text)');
}).find('img.bullet');

您需要使用.filter()函数和:contains()方法查找包含的文本。


Here is a demo尝试点击图片。