Determine How Many Columns are in a Given Table

by serio

HTML

<table border='1'>
    <tr>
        <td>What up G?</td>
        <td>This is an awesome test</td>
        <td>Yeeah, woot woot woot!</td>
        <td>Yeeah, woot woot woot!</td>
    </tr>
    <tr>
        <td colspan='4'>This is an awesome test</td>
    </tr>
    <tr>
        <td colspan='3'>What up G?</td>
        <td>This is an awesome test</td>
    </tr>
    <tr>
        <td>What up G?</td>
        <td>This is an awesome test</td>
        <td colspan='2'>Yeeah, woot woot woot!</td>
    </tr>
</table>

JavaScript

$(function() {
    var how_many = 0;
    $('table tr').each(function(i) {
        var kids = $( this ).children();
        if( kids.length > how_many ) how_many = kids.length;
    });
    
    alert( 'there are ' + how_many + ' columns' );
});