简体   繁体   中英

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">

$('#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() :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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