ua_boaz ua_boaz - 1 year ago 70
Javascript Question

jquery find specific columns in a table column in tbody element

var html_table =
"<table class='table'>" +
"<thead>" +
"<tr><th>#</th><th>First</th><th>Second</th><th>Third</th><th>Fourth</th><th>Fifth</th></tr></thead>" +
"<tbody>" +
"<tr><td ></td><td></td><td>Pitt</td><td>35</td><td>New York</td><td>USA</td></tr>" +
"</tbody>" +

var $html_table = $(html_table);
var first_column= $html_table.find('???');
var second_column= $html_table.find('???');

So i have above table in javascript and using jquery to get the first and third columns. But find() method doesn't seem to be flexible enough to get first and third column inside tbody element

Answer Source

You can get access to all td of column with next code:

var columnNumber = 0; //first column
$.each($html_table.find("tr"), function(){
  var tdOfCurrentColumn = $(this).children().eq(columnNumber);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download