开发者

jQuery: what if I don't have mouseleave function?

I'm using Drupal for a website and I can only use jQuery 1.2.7 (not the most recent versions).

I want to fade in / fade out a div element and I'm using mouseover / mouseout functions.

However, this element contains some children and when I move the mouse over it, the开发者_Go百科 mouseout function is triggered, because I'm moving over one of its children.

Since I don't have mouseleave function, how can I solve this issue ?

thanks

Updated:

<div id="parent">
  <p> blabla </p>
  <div><a> blabla </a>
  <p> blabla </p>
</div>


You can test which element is the target, and act depending on what that element is. In the below example the span is a child of the anchor, but if the span is mousovered the second alert fires.

<a href="#">Blah blah <span>hehehhehe</span></a>​

$("a").mouseover(function(e) {
    if(e.target == this) {
        alert('mouseover is on the anchor, do something special');   
    } else {
        alert('got a ' + e.target.tagName + ' and not a ' + this.tagName);
    }
});​

Try it here: http://jsfiddle.net/ss2F2/1/


jQuery (since 1.0) has had the hover event to handle exactly this scenario. In addition, mouseleave has been in jQuery since 1.0 as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜