html - How to replace text in a column (inside a table) with Javascript without any ID -
the code below shows rendered html (from compiled asp .net code). not able make changes including adding new attributes id.
i still javascript because there no unique id column, not replace underscore text "____________" other text.
the plan replace underscore in column 3 each row other text. there way identify column 3 javascript?
thank you.
<table width='100%'> <tr> <td align="left" valign="top" class='clsreadonly'>row 1 </td> <td align="left" valign="top" class='clsreadonly'> abc </td> <td align="left" valign="top" class='clsreadonly'> __________________________ </td> </tr> <tr> <td align="left" valign="top" class='clsreadonly'>row 2 </td> <td align="left" valign="top" class='clsreadonly'> def </td> <td align="left" valign="top" class='clsreadonly'> __________________________ </td> </tr> <tr> <td align="left" valign="top" class='clsreadonly'>row 3 </td> <td align="left" valign="top" class='clsreadonly'> ghi </td> <td align="left" valign="top" class='clsreadonly'> __________________________ </td> </tr> </table>
it depends on trying accomplish. if how table look, following:
var cells = document.getelementsbyclassname('clsreadonly'); cells[2].innerhtml = "row1 column3"; cells[5].innerhtml = "row2 column3"; cells[8].innerhtml = "row3 column3"; if don't know how many columns start with, have this:
var rows = document.getelementsbytagname('tr'); (var i=0; i<rows.length; i++) { var cells = rows[i].getelementsbytagname('td'); cells[2].innerhtml = 'row'+(i+1)+' column3'; } jquery make easier, can select tag, parent, etc. of course, can of in plain javascript, takes lot more work.
Comments
Post a Comment