Answers for "add class on column depend on column count"

0

add class on column depend on column count

$('.table').each(function( index ) {
        var ColumnCount = $(this).find('tr td').length;
        if(ColumnCount == 2){
            $(this).find('tr td').each(function(){

                $(this).addClass('col col-md-6');
            });
        }
        if(ColumnCount == 3){
            $(this).find('tr td').each(function(){

                $(this).addClass('col col-md-6 col-md-4');
            });
        }
        if(ColumnCount == 4){
            $(this).find('tr td').each(function(){

                $(this).addClass('col col-md-6 col-md-3');
            });
        }
    });
Posted by: Guest on July-28-2021

Code answers related to "add class on column depend on column count"

Browse Popular Code Answers by Language