Link to home
Create AccountLog in
Avatar of Simon Leung
Simon Leung

asked on

use JQuery to query HTML row

Is there any example on using JQuery to display each column of a selected row in a HTML table ?

Thx
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Yes, give the table an ID (e.g. "theTable") or use other selector, and the following code can do the trick:
$(document).ready(function(){
  $("#theTable tr").click(function(e){
    var result = "";
    $.each($(this).children(), function(idx, obj){
      result += idx + ": " + $(obj).text() + "\n";
    });
    $("#resultText").val(result);
  });
});

Open in new window

see attached example
test-29164240.html
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account