How can I find current element on mouseover using jQuery?

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

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

8条回答
  •  旧时难觅i
    2020-12-24 07:42

    This is my version:

    function handler(ev) {
    var target = $(ev.target);
    var elId = target.attr('id');
    if( target.is(".el") ) {
       alert('The mouse was over'+ elId );
    }
    }
    $(".el").mouseleave(handler);
    

    Working fiddle: http://jsfiddle.net/roXon/dJgf4/

    function handler(ev) {
        var target = $(ev.target);
        var elId = target.attr('id');
        if( target.is(".el") ) {
           alert('The mouse was over'+ elId );
        }
    }
    $(".el").mouseleave(handler);
    .el{
        width:200px;
        height:200px;
        margin:1px;
        position:relative;
        background:#ccc;   
        float:left;
    }
    
    

    Hover an element and refresh the page, than move your mouse away.

提交回复
热议问题