How can I find current element on mouseover using jQuery?

前端 未结 8 1740
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 07:10

How can I get the class name of the current element that is on mouseover? For example \"enter<

8条回答
  •  盖世英雄少女心
    2020-12-24 07:41

    Do you want the class name of the div on which the mouseover event occurs? If that is the case then refer this,

    HTML

    aaaaaaaa
    bbbbbbbbb

    jQuery

    $(document).on('mouseover', 'div', function(e) {
        console.log($(e.target).attr('class'));
    });
    

    jsFiddle

    I have used mouseover event with target

    e.target gives the element on which that event occurs

    If you want to get the class name of div after leaving the mouse from it then use "mouseleave" event instaed of "mouseover"

提交回复
热议问题