how to toggle attr() in jquery

前端 未结 10 1930
独厮守ぢ
独厮守ぢ 2021-01-30 15:50

I have a simple add attribute function:

$(\".list-toggle\").click(function() {
    $(\".list-sort\").attr(\'colspan\', 6);
});

My question is:

10条回答
  •  时光说笑
    2021-01-30 16:43

    If you're feeling fancy:

    $('.list-sort').attr('colspan', function(index, attr){
        return attr == 6 ? null : 6;
    });
    

    Working Fiddle

提交回复
热议问题