简体   繁体   English

jQuery不根据子元素属性进行选择

[英]jQuery not selecting based on sub-element attribute

I'm trying to modify this code, such that, it does not select rows that have the child <td colspan="12"> 我正在尝试修改此代码,以便它不会选择具有子<td colspan="12">

$('#my-table tbody>tr').hide();

I've tried this: 我已经试过了:

$('#my-table tbody>tr:not(tr>td[colspan="12"])').hide();

and several similar variations with small tweaks, but I can't get the syntax right. 以及一些类似的细微调整,但我无法正确理解语法。 What am I doing wrong? 我究竟做错了什么?

使用:has():

$('#my-table tbody>tr:not(:has(td[colspan=12]))').hide();

If you need more flexibility or a more complex condition than @roasted's answer, you can use .filter() : 如果您需要比.filter()答案更大的灵活性或更复杂的条件,则可以使用.filter()

$('#my-table tbody>tr').filter(function() {
  return $(this).children('td[colspan="12"]').length === 0;
}).hide();

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

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