0

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

1
  • What data structures have you established? Commented Jun 23, 2010 at 16:04

1 Answer 1

2

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()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.