You can use the :first-child
selector (http://www.w3schools.com/cssref/sel_firstchild.asp), it'll select the first table cell for each row.
How to get text from the first column in a table?
Question
There is a table in a webpage (in my case, http://developer.chrome.com/extensions/api_index) and I want to obtain all the method names in Stable APIs. So I want to get an array, the elements of which are the things in the first column.
How to do it?
$("table:eq(5) tr td:eq(0)")
this code does not work, because it does not get text from all the first td elements in all rows, but only in one row. What to do?
Solution 2
OTHER TIPS
you can try
$(table).find('td:first').text() //can you table id or class
can iterate in a loop for all rows to get first cell value
var array = new Array();
$('table tr').each(function () {
var firstCell = $(this).find('td').first();
array.push($firstCell.text());
});
var array = [];
jQuery('table tr').each(function () {
var $row = $(this);
var $firstCell = $row.find('td:first');
array.push($firstCell.text());
});
Try:
var a = new Array();
$("table:eq(5) tr td:first-child").each(
function(){
a.push($(this).text())
});
You can loop through all the table rows like this:
$("#tableId > tbody > tr").each(function(){
var name = $(this).find("td:first").text();
console.log("Method name: "+name);
});
You can initialize an array globally and save in that array in loop. Hope this helps.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow