Hi kcharles,

you need to concatenate the variable, n, with the rest of the selector expression. Otherwise, it's treated as the string, "n". Try this:

$("#filterTable tbody tr td:nth-child(" + n + ")").each(function(){

Also, you probably don't need either the "tbody" or "tr" part in there since, presumably, any td is going to be within a tr and a tbody.

--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Sep 17, 2008, at 1:01 PM, kcharles wrote:


I switch between var n = 2; nth-child(n) and nth-child(2) and get
different behavior.
Any suggestions/work arounds?
Thanks!

Here is the code:

<html>
<head>
<title>nth child</
title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
//Add input box for each column

$(function(){
         var n = 2;
//       $("#filterTable tbody tr td:nth-child(2)").each(function(){
         $("#filterTable tbody tr td:nth-child(n)").each(function(){
                 $(this).append("this row");
         });
});





</
script>
</
head>
<body>


<table id="filterTable"  width="580" border=1>
<thead>
<tr>
<th>Number</th>
<th>Letter</th>
<th>More</th>
</tr>
</thead>

<tbody>
<tr>
<td>1</td>
<td>A</td>
<td>A</td>
</tr>

<tr>
<td>2</td>
<td>A</td>
<td>B</td>
</tr>

<tr>
<td>3</td>
<td>B</td>
<td>3</td>
</tr>

<tr>
<td>4</td>
<td>B</td>
<td>D</td>


</tr>
</tbody>
</table>


</
body>
</html>

Reply via email to