Prevent table row onclick event to fire when clicking button inside the row

前端 未结 4 623
后悔当初
后悔当初 2021-02-01 17:01

I have a table row with ONCLICK event (that toggles additional data below). Inside one of the row cells I have a button (when clicked is performing an AJAX action). When I click

4条回答
  •  借酒劲吻你
    2021-02-01 17:26

    If you use jQuery, you can just do this instead:

    tbody.on('click', 'tr', function (e) {
        let target = $(e.target);
        if (target.is('i') || target.is('button') || target.is('a') || target.hasClass('select-checkbox')) {
            return;
        }
        //your stuff here
    });
    

提交回复
热议问题