Getting the class of the element that fired an event using JQuery

后端 未结 6 1377
独厮守ぢ
独厮守ぢ 2021-01-30 08:04

is there anyway to get the class when click event is fired. My code as below, it only work for id but not class.

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 08:47

    Try:

    $(document).ready(function() {
        $("a").click(function(event) {
           alert(event.target.id+" and "+$(event.target).attr('class'));
        });
    });
    

提交回复
热议问题