You're not really referencing the 'n' variable you just defined, as you're passing a string.
var n = 2; $("#filterTable tbody tr td:nth-child("+n+")").each(function(){ On Sep 17, 2:24 pm, kcharles <[EMAIL PROTECTED]> 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>