javascript - how to find table tag td values useing jQuery filter selecter -
<table> <tr> <td>calories </td> <td>targetvalue1</td> </tr> <tr> <td>protein</td> <td>targetvalue2</td> </tr> <tr> <td>protein</td> <td>targetvalue3</td> </tr>
hi how can select second td values??
i tried
$.each($("#nutritab tbody tr td:eq(1)"),function(i , item){ alert($(item).text()); });
but return first values ....
use
nth-child
selector instead of:eq(index)
the :nth-child(n)
selector matches every element nth child()
(index starts 1
)
the :eq(index)
selector selects element @ index n within matched set.(zero-based index
)
$.each($("#nutritab tr td:nth-child(2)"), function(i, item) { alert($(item).text()); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table id='nutritab'> <tr> <td>calories</td> <td>targetvalue1</td> </tr> <tr> <td>protein</td> <td>targetvalue2</td> </tr> <tr> <td>protein</td> <td>targetvalue3</td> </tr> </table>
Comments
Post a Comment