tags:

views:

30

answers:

2

hi,

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 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>
A: 

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.

tvanfosson
with mouseleave I get function doesn't exist - mouseout works perfectly
Patrick
@Patrick - I just confirmed (via http://ajax.googleapis.com/ajax/libs/jquery/1.2/jquery.js) that mouseleave is in 1.2, as is hover. Are you sure it isn't an even earlier version you have?
tvanfosson
jQuery 1.2.6 - New Wave Javascript. I get respectively "mouseleave is not a function" and if I use .hover() I get "g is undefined"
Patrick
@Patrick - is it possible that you've defined mouseleave elsewhere and it's conflicting with the function definition? You obviously have hover() defined and the definition of hover uses mouseleave so I don't see how it's possible that you don't have it defined unless you've edited your jQuery and have introduced a syntax error that keeps it from being defined. Try using 1.2.6 from Google Code and see if that works (link above).
tvanfosson
ok, you convinced me it is there. I dunno what's going on, I'm just using Drupal CMS which has 1.2.6 by default and i haven't hacked the code
Patrick
any tip to fix this ?
Patrick
ok hover worked. the strange error was because I didn't implement it correctly with 2 functions inside, instead of 1.... terrible to debug. Lost all day.
Patrick
+1  A: 

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/

karim79
so, your answer is not solving my issue right ? I actually need when it is on a children element .. should I use something like e.target == this.children() ? thanks
Patrick
@Patrick - it's hard to say, I don't know exactly what you mean from the question. If you could show your markup structure and provide a bit more context it will be more clear to me.
karim79
ok, i've added some structure to the question. Basically the popup menu is disappearing now when I move the mouse out from a children. Instead it should disappear only when I move it out from the parent (and I'm really outside the element).
Patrick