0

I have a table that has a class name partnerGridClass. I would like to set one of the rows background colors that corresponds to a certain index n. n is just a javascript variable.

$("table.partnerGridClass tbody tr:nth-child(n)").css("background-color", "#CCCCCC");

What I have above is not working for selecting the nth row. Does anyone know how to do this?

2 Answers 2

1

try

$("table.partnerGridClass tbody tr:nth-child("+n+")")
Sign up to request clarification or add additional context in comments.

Comments

0

Well the 'n' obviously must be substituted with the actual number. So if n is a variable, you need to write:

$("table.partnerGridClass tbody tr:nth-child(" + n + ")").css("background-color", "#CCCCCC");

Even then, keep in mind that it starts at 1, so if n=0 is the first, you'd need to add one to it first.

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.