How can I find current element on mouseover using jQuery?

前端 未结 8 1756
爱一瞬间的悲伤
爱一瞬间的悲伤 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:50

    Get the position of element on mouseover and then get the class name

    A
    DIV
    $('#wrapper').mouseover(function(e) { var x = e.clientX, y = e.clientY, elementOnMouseOver = document.elementFromPoint(x, y); elementClass=$(elementOnMouseOver).attr('class'); alert(elementClass); });

    JSFiddle: http://jsfiddle.net/ankur1990/kUyE7/

    If you don't want to apply this only on wrapper div but on whole window/document, then you can replace wrapper with window/document

     $(window).mouseover(function(e){});
    

提交回复
热议问题