Reputation: 38210
I have a table with thead with first th colspan = 1. I want to set it programmatically to value 2 : it doesn't work, how to do this ?
Here's source code :
https://jsfiddle.net/Lgof8m6q/
<table>
<thead>
<tr>
<th scope="col" colspan="1">TITLE</th>
</tr>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
javascript :
var myTable = document.getElementsByTagName('table')[0];
var myThead = myTable.getElementsByTagName('thead')[0];
_tr = myThead.getElementsByTagName("TR")[0];
_th = _tr.getElementsByTagName("TH")[0];
_th.colspan = 2;
Upvotes: 1
Views: 433
Reputation: 2978
Javascript DOM elements has a special method for setting attributes, which is setAttribute('<attribute>','<value>')
_th.setAttribute("colspan", "2");
check this fiddle:
https://jsfiddle.net/Lgof8m6q/7/
Upvotes: 4