Getting data-* attribute for onclick event for an html element

前端 未结 7 1211
一个人的身影
一个人的身影 2020-12-22 23:33

       Click to do something

I wan

7条回答
  •  旧时难觅i
    2020-12-23 00:13

    Check if the data attribute is present, then do the stuff...

    $('body').on('click', '.CLICK_BUTTON_CLASS', function (e) {
                            if(e.target.getAttribute('data-title')) {
                                var careerTitle = $(this).attr('data-title');
                                if (careerTitle.length > 0) $('.careerFormTitle').text(careerTitle);
                            }
                    });
    

提交回复
热议问题