Jitendra Vyas
Jitendra Vyas

Reputation: 152617

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">
      });

Upvotes: 0

Views: 413

Answers (2)

Mathias Bynens
Mathias Bynens

Reputation: 149484

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');

Upvotes: 4

David Hedlund
David Hedlund

Reputation: 129782

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

which can be reduced to

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

Upvotes: 1

Related Questions