user374412
user374412

Reputation: 1

getting values from an array (JS / jQuery)

I'm passing an array to a function I want to be able to show or hide columns in a table depending on what's passed.

So, if I pass 1,3,4 columns 1 3 and 4 should show - column 2 should not.

I can handle the show/hide bit. I'm just not sure how to grab the values from the array

Upvotes: 0

Views: 105

Answers (1)

Bob Fincheimer
Bob Fincheimer

Reputation: 18056

A simple loop that looks at all the values. jQuery can use the nth-child selector to get the n-th item in a group. Not sure about the selector, but use [] notation to get the values:

var i = 0;
for(i = 0; i < array.length; i++) {
    $('tr td:nth-child(' + array[i] + ')').hide();
}

EDIT

changed the :eq to :nth-child()

Upvotes: 2

Related Questions