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
HTMLjQuery

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Brian Tao

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
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck