javascript - Add new column to HTML table which has not table id -


how can add new column in below code, need happen if there no table id or tr id or td id.

please check , tell me

<p>click button insert new cell(s) @ beginning of table row.</p>  <table>   <tr>     <td>first cell</td>     <td>second cell</td>     <td>third cell</td>   </tr> </table><br>  <button onclick="myfunction()">try it</button>  <script> function myfunction() {     var row = ??????????????     var x = row.insertcell(0);     x.innerhtml = "new cell"; } </script> 

you can use getelementsbytagname access tables.

var row = document.getelementsbytagname("table")[0].rows[0]; 

https://jsfiddle.net/4rmt4xmj/1/


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -