简体   繁体   中英

How to add exception in this jquery code?

How to add exception in this jquery code?

$(function() {
        $("table tr:nth-child(even)").addClass("striped");
      });

this code is applying on all tables.

but for specific pages i don't want strip effect.

I've different body id on each page.

I want to know how to add exception for a id.

$(function() {
        $("table tr:nth-child(even)").addClass("striped");
        //I want to add exception to not to add striped class to only to page with <body id="nostrip">
      });

David's solution works if you only have to filter for one ID. However, since you have several body IDs for which you don't want to use the script, you can use something like this:

$('body:not(#id1, #id2, #id3) tr:even').addClass('striped');
$('body[id!=nostrip] table tr:nth-child(even)').addClass("striped");

可以减少到

$('body[id!=nostrip] tr:even').addClass("striped");

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