tags:

views:

49

answers:

2

Hi, so the problem is, that i want to insert a new row after another row in my html here is my html

<html> 
  <head> 
    <title>JQuery Problem 2</title> 
    <script type="text/javascript" src="jquery-1.4.min.js"></script> 
    <script type="text/javascript" src="problem2.js"></script> 
  </head> 
  <body> 
    <div id="game"> 
      <form onsubmit="return false"> 
        <p> 
          Guess:
          <input type="text"/> 
          <input type="submit" value="Go"/> 
        </p> 
        <p> 
          <strong>Number of guesses:</strong> 
          <span>0</span> 
        </p> 
        <p> 
          <strong>Last guess:</strong> 
          <span>None</span> 
        </p> 
        <table border="1" cellpadding="4" cellspacing="1" style="width: 400px"> 
          <tr> 
            <th>Guess</th> 
            <th>Result</th> 
          </tr> 
        </table> 
      </form> 
    </div> 
  </body> 

My question is I want to insert a new row after the tr with the headers.

A: 

Something like this, but you need to construct the row yourself:

$(function(){
   $('tr:first').after('<tr><td>0</td><td>0</td></tr>');
});
Nick Craver
Question, if I was to replace the zero with jquery object variables, I can't seem to get them interpolated, any ideas how?
Zerobu
@Zereobu - If you do `$('tr:first').after('<tr><td>' + var + '</td><td>' + var2 + '</td></tr>');` it should work, alternatively generate the `<td>` separately then append the whole row like this: `$('<tr></tr>').append($('<td></td>').text('0')).append($('<td></td>').text('0')).appendTo('table');` replace those `'0'` with variables.
Nick Craver
A: 
$('#game table').append ($('<tr><td>col 1</td><td>col 2</td></tr>));
mathroc