使用jQuery隐藏具有特定内容的所有内容

时间:2016-04-20 16:10:43

标签: jquery html css

寻找有关如何隐藏特定表格中与以下示例内容(6个空格)匹配的所有<td>的建议:

<td id="" class="">      </td>

Firebug显示为

<td class="" id="">

</td>

3 个答案:

答案 0 :(得分:4)

如果您想根据<td>id属性定位实际的class元素,可以使用attribute equals selector来处理:{/ p>

// Hide any <td> elements that have an empty ID and class attributes
$('td[id=""][class=""]').hide();

同样,如果您想根据内容定位这些元素,那么您可以使用contains()选择器:

// Hide any elements that contain six consecutive spaces
$('td:contains("      ")').hide();

但是,如果您想定位包含完全该内容的元素,您可能需要通过filter()调用来处理它:

// Hide any <td> elements that have content that is exactly six spaces
$('td').filter(function(){ $(this).text() == '      '; }).hide();

答案 1 :(得分:0)

你应该使用jQuery contains

类似的东西:

  $( "td:contains('      ')" ).css( "display", "none" );

答案 2 :(得分:0)

如果由于某种原因$.map( dimensions, function( value, index ) { ary.push([index, value]) }); 不起作用,您可以在循环中使用jquery的:contains方法来检查内容:

.html()
相关问题