Friday 15 May 2015

html - Javascript: Set ID to a child existing table -



html - Javascript: Set ID to a child existing table -

i need assign/set unique id kid tables per javascript. main parent table has id kid tables , farther kid tables within kid tables don't.

how can set id 1st kid , sec kid tables "on page load"?

<table id="main parent table"> <tbody> <tr> <td> <table> <tbody> <tr> <td> <table> <tr> <td></td> </tr> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody>

you looking (fiddle here) :

$('table').each(function(eq, el) { el = $(el); if(typeof(el.attr('id')) === "undefined") { el.attr('id', 'table-' + eq); } });

you check every table on site , if has no id, assign id of "table-" each 1 in tree.

javascript html table identifier

No comments:

Post a Comment