javascript - getting row index of a specified row using java script -
i want rowindex of passed row number. tried using rowindex[2]. dont it. here code. please me. in advance..
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <!-- jquery --> </head> <body> <div id="main"> <button onclick = "replacecontent('tabledata')"> click load </button> <table id="tabledata"> </table> </div> <script> function replacecontent(tableid) { var targetdiv = $('#' + tableid).closest("div").prop("id"); var content = "<table> <tr> <td> one</td></tr><tr> <td> one</td></tr><tr> <td> one</td></tr><tr> <td> one</td></tr><tr> <td> one</td></tr></table>"; $('#' + targetdiv).html(content); var x = document.getelementbyid("tabledata").rows[1]; alert (x.rowindex); } </script> </body> </html>
if have <table id="tabledata">
inside html, there's no need create 1 dynamically, use existent 1 cached element reference.
(also, remember close tag </table>
)
function replacecontent(tableid) { var $table = $("#"+ tableid); // don't put <table> inside content var content = "<tr><td> one</td></tr><tr> <td> two</td></tr><tr> <td> three</td></tr><tr> <td> four</td></tr><tr> <td> five</td></tr>"; $table.html(content); var x = $table.find("tr").eq(1); // second row html test alert (x.html()); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="main"> <button onclick="replacecontent('tabledata')"> click load </button> <table id="tabledata"></table> </div>
Comments
Post a Comment