1

I have an html table followed by a button that says "Add Row" below it.

When I click on the button, I would like to add a new row onto the html table but first I need to get the html table id above.

Is there anyway in jQuery to say "Give me the id of the html table right before this button"?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
leora
  • 188,729
  • 360
  • 878
  • 1,366

1 Answers1

4
$("button").click(function(){
  var tblID = $(this).prev("table:first").attr("id");
});
Sampson
  • 265,109
  • 74
  • 539
  • 565