简体   繁体   中英

jquery - Hide checkbox for table row?

在此处输入图片说明

Hello, how do I hide the checkbox for the table row that always contains the word "Fixed" as a link? Please see screenshot. The ID and names are dynamic and always change. I tried this but had no luck:

$( "tr:contains('Fixed')" ).find( ":checkbox" ).css( "display", "none" );

Something like this should work:

$('a').filter( function() {
    return ~$(this).text().toLowerCase().indexOf('fixed');
} ).closest('tr').find(':checkbox').hide();

The .toLowerCase() makes it case-insensitive, and the ~ is there because if indexOf() doesn't match the string, it returns -1 (0 means "at position 0"), so the bitwise NOT converts -1 into the falsey value of 0, and everything else into truthy values.

You can improve this by adding a selector to the front so it doesn't crawl every single <a> tag - something like $('table').find('a') or better yet the ID, or something more identifiable.

$( "tr a:contains('Fixed')" ).find( ":checkbox" ).css( "display", "none" );

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