I have following code of HTML,
<table>
<tr>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td colspan="2">one</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td colspan="2">two</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td colspan="2">three</td>
</tr>
</table>
What I really want is to count the “colspan”, and take the those contents from those table with JavaScript only, no jquery and mootool please. Thanks you.
I have got the answer for this, can we optimize to be shorter code or just simply the code?
var tds = document.getElementsByTagName( 'td' );
var colspanCount = 0;
var valuecount = 0;
for( i=0; i<tds.length; i++ ) {
myvalue = (tds[i].hasAttribute( 'colspan' ));
if (myvalue == true) {
valuecount += 1;
}
}
document.write('my value is ' + valuecount);
I think using jQuery would be best, but something like this should work:
Please note that this is untested.