views:

106

answers:

2

In my functions.js I have:

$(document).ready(function() {      
  $("#cat").hover(function() {
    $("#kiti").show();  
  })
  $("#kiti").mouseout(function() {
    $("#kiti").hide();      
  })                                 
})

Html file:

<a id="cat" href="#">category</a>
<div id="kiti">
    <a href="#">sub1</a>
    <br /><a href="#">sub2</a>
</div>

Why, when I hover over sub1, sub1 and sub2 hide? If it's simple text, it's ok. I hope you got my question.

Edit: By the way. Is there any way to make something like die(); or exit(); from php in javascript to stop execution?

+5  A: 

$.hover() takes two arguments. If you just want to use the first, use $.mouseover() instead.

$(function(){
  $("a#cat").mouseover(function(){
    $("#kiti").show(); // shows <div id="kiti">...sub1...sub2...</div>
  });
  $("#kiti").mouseleave(function(){
    $(this).hide();    // hides <div id="kiti">...sub1...sub2...</div>
  });
});
Jonathan Sampson
It's probably worth noting that jQuery 1.4 (which is still in Alpha) supports passing just one function to `hover()`.
J-P
It still doesn't work. When I put mouse pointer on <a href="#">sub1</a> all subs hides.
hey
@Tomas, try my updated solution.
Jonathan Sampson
Unbelievable! It's finally working, thank you so much!By the way, can you explain, what is the difference between mouseleave and mouseout?
hey
+3  A: 

mouseout is the wrong event - it is triggered when you hover over a child element.
Use mouseleave instead:

$("#cat").mouseenter(function() {
    $("#kiti").show();  
});
$("#kiti").mouseleave(function() {
    $("#kiti").hide();      
});

See it here: http://jsbin.com/irexo
Documentation here: http://docs.jquery.com/Events/mouseout

Kobi
+1, beat me to the punch.
Aaronaught
Happens all the time. You'll get me next time :)
Kobi
Thank you. And can you tell me, what I have to add that when I put away mouse pointer from category instantly?
hey