I seen a lot of post talk about my problem but any of one work for me.
I've this html table, I would to get the values under the cell (th) "Index". How can I use jQuery for making this:
<table id="htmlTable">
<caption>Informations des hotspots</caption>
<thead>
<tr>
<th>Index</th>
<th>Nom du hotspot</th>
<th>Image du hotspot</th>
</tr>
</thead>
<tbody>
<tr id="0">
<td>0</td>
<td>Hotspot Fribourg Centre</td>
<td>../images/logos_hotspot/logo_wifi_centre.png</td>
<td>
<input type="button" value="supprimer" />
</td>
</tr>
<tr id="1">
<td>1</td>
<td>Hotspot Avry Centre</td>
<td>../images/logos_hotspot/logo_wifi_avry.png</td>
<td>
<input type="button" value="supprimer" />
</td>
</tr>
</tbody>
</table>
How can get TD value from TR in jQuery? var Something = $(this). closest('tr'). find('td:eq(1)').
data. find(selector); Then to find the value of different cells in a row, we'll have to specify the cell which will be done using the eq() method in jQuery. This method returns the value with a specific index number of the selected elements.
I Think This Will Help You
var MyRows = $('table#htmlTable').find('tbody').find('tr');
for (var i = 0; i < MyRows.length; i++) {
var MyIndexValue = $(MyRows[i]).find('td:eq(0)').html();
}
Try this:
var text = $('#htmlTable tr th:first').text(); // = "Index"
Example fiddle
To get the content of the <th>
tag itself:
$('#htmlTable th:first').html()
To traverse the subsequent <td>
tags and get their values:
$('#htmlTable tr:gt(0)').each(function(){
console.log($('td:first', $(this)).html());
});
Or fiddle with it yourself: http://jsfiddle.net/chaiml/p2uNv/4/
by this th relative td value come
var tharr=[];
$("#htmlTable").find("tbody tr").each(function(){
tharr.push($(this).find("td:eq(0)").text());
});
alert(tharr.join(",")); //by this you get 0,1
and if you want only th value do this
$('#htmlTable tr th:first').text();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With