dacami
dacami

Reputation: 75

jquery select and exclude multiple nth-childs

Is there a way that i can select multiple nth-childs at once like:

    $("#table").find("tr > :not(td:nth-child(1,3,5))");

which doesn't work

I want to select all td in each row but not for column 1,3,5 (this can be any combination).

Is there a way to do this? I cannot assign classnames.

thanks for any help!

UPDATE:

I want to search in all rows of a table, but exclude some columns.

I have this code right now:

    elem.keyup(function() {

    $(options.table).find("tr").hide();
    var data = this.value.split(" ");
    var jo = $(options.table).find("tr > :not(td:nth-child("+cols+"))");

    $.each(data, function(i, v){

    jo = jo.filter(":containsIgnoreCase('"+v+"')");

    });

    jo.parent().show();
    });

It works when I pass a single value, but i want to exclude multiple columns.

thanks

Upvotes: 1

Views: 866

Answers (1)

ahren
ahren

Reputation: 16959

From your example, it looks like you're trying to exclude the odd numbers. Try:

$("#table").find("tr > :not(td:nth-child(odd))");

Although, it may be more efficient to just select the even ones.

$("#table").find("tr > td:nth-child(even)");

You can also use formulas in nth-child. See this link for more detail.

Okay, as per comments below/clarification on the question, here is another solution.

$("#table").find("tr > td").filter(function(index){
   return index == 1 || index == 2 || index == 5;   
});

Upvotes: 1

Related Questions