views:

55

answers:

2
<html lang="en">
<head>
<style>
#thisdiv {padding:10px; margin:-15px 0 0 40px; background-color:#333; position:absolute; display:none;}
div.block {margin-top:10px; width:200px;}
div#thisdiv a {color:#fff;}
</style>
</head>
<body>

<div id ="one" class="block"><a href="">one</a></div>
 <div id="thisdiv">hello</div>
<div id ="two"class="block">two</div>
<div id ="three"class="block">three/div>


<script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
<script>
$(document).ready(function() {
  $('#one').hover(function() {
   $('#thisdiv').fadeIn(400);
  }); 

  $('div:not(#thisdiv)').mouseleave(function() {
   $('#thisdiv').fadeOut(400) 
  });
});
</script>
</body>
</html>

#thisdiv doesn't fadeOut. I could have used the following, but it only fades out if the cursor mouse outs of #thisdiv. Is there any way i can solve this so when the cursor navigates away from anyway, the div still fade out.

$('#thisdiv').mouseleave(function() {
   $('#thisdiv').fadeOut(400) 
  });

I couldn't figure out what's why jquery's :not selector is not doing what I wanted to. Am i using it wrongly?

+2  A: 

1 - You need to use mouseover, not hover for the first binding:

  $('#one').mouseover(function() {
     $('#thisdiv').fadeIn(400);
  }); 

hover accepts two function parameters (mouseover/mouseout).

2 - Your closing div tag at the end of your markup is broken (missing a <):

<div id ="three"class="block">three/div> <-- here

I tested your code having made the above modifications, and it seems to work as you want it to (if I've understood correctly). Test it here.

karim79
sorry about the broken markup, i had to delete away a href tags because stackoverflow don't allow me to have more than 1 a href in a post.Your link example works fine, but i guess i did not make it clear tho. #thisdiv only disappears when i have to move my cursor to the div and mouse out.when i mouse over #one, #thisdiv appears, but when i move to #two, #thisdiv still stays there. This is the problem and at the same time, #thisdiv is a div that has a link for user to click.I could only though of using :not selector so when i mouseout to anywhere except #thisdiv, #thisdiv will disappear.
kim
A: 

if you are going to explicitly set the time, you will need to pass it in as a hash parameter. Otherwise you can use 'slow', 'fast' or the default which is 400.

$('#my_button').mouseleave(function(){ $(this).fadeOut({duration:1000}) })