How to get cell value in html table using jQuery

I saw a lot of posts about my problem, but any of them worked for me.

I have this html table, I would get the values ​​under cell (th) "Index". How can I use jquery to create 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> 
+6
source share
5 answers

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(); } 
+12
source

this relative value of td will come out

  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 to get only the th value,

 $('#htmlTable tr th:first').text(); 
+2
source

Try the following:

 var text = $('#htmlTable tr th:first').text(); // = "Index" 

Script example

+2
source

To get the contents of the <th> tag itself:

 $('#htmlTable th:first').html() 

To pass the subsequent <td> tags and get their values:

 $('#htmlTable tr:gt(0)').each(function(){ console.log($('td:first', $(this)).html()); }); 

Or play with it yourself: http://jsfiddle.net/chaiml/p2uNv/4/

+2
source

Try the code below.

 $(document).on("click", "[id*=tableId] tr", function () { var a = $(this).find("td").eq(3).children().html(); alert(a); }); 
0
source

Source: https://habr.com/ru/post/958546/


All Articles