how to toggle attr() in jquery

前端 未结 10 1939
独厮守ぢ
独厮守ぢ 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:35

    For what it's worth.

    $('.js-toggle-edit').on('click', function (e) {
        var bool = $('.js-editable').prop('readonly');
        $('.js-editable').prop('readonly', ! bool);
    })
    

    Keep in mind you can pass a closure to .prop(), and do a per element check. But in this case it doesn't matter, it's just a mass toggle.

提交回复
热议问题