Thanks for the suggestions, but I haven't found the answer yet. > Try: > alert( $(this).attr('id') );
This displays "undefined" in the alert box. > var rw = $('<tr id="' + row_id + '"><td>row ' + i + '</td></tr>').click( > function() { alert(row_id); } ); This displays "row4" for all rows in the alert box. > $('#t1 tr#row'+ i).click( function(){ alert( this.id); } ); This displays "undefined" in the alert box. original post: > > > > I'm building a dynamic table, assigning each row a unique ID based on > > the value of the counter, and trying to display the row id in an alert > > box when a row is clicked: > > > $(function() { > > for (i=0; i<5; i++) { > > var row_id = 'row' + i; > > var rw = '<tr id="' + row_id + '"><td>row ' + i + '</td></tr>'; > > $('#t1').append (rw); > > $('#t1 tr#' + row_id).click( function() > > { alert(row_id); } ); > > } > > }); > > > The problem is that although I get a different row_id for the id of > > each row, the alert box is always displaying "row4". I understand why > > this is happening; this was the value at the last pass through the > > loop. > > > What can I do to have it display the correct value? > > -- > Benjamin Sterlinghttp://www.KenzoMedia.comhttp://www.KenzoHosting.com