test
test

Reputation: 2466

jQuery mouseenter second time then do this

Here is my code: http://jsfiddle.net/sZKeM/1/

So basicly it shows box when I hover button and when I hover out from box it will hide. I want to hide box when I hover again the button and if I hover again it will show box again.

$('.btn').mouseenter(function(){
   $('.box').css('display','block');
});

$('.box').mouseenter(function(){
   $('.box').css('display','block');
});

$('.box').mouseleave(function(){
   $('.box').css('display','none');
});

Upvotes: 0

Views: 179

Answers (3)

net.uk.sweet
net.uk.sweet

Reputation: 12431

It's difficult to understand exactly what you want from your question and comments. Is this the behaviour you're looking for:

http://jsfiddle.net/nSfrK/

Upvotes: 1

mschr
mschr

Reputation: 8641

$('.btn').mouseenter(function(){
   var visible = $('.box').css('display') == "block"
       $('.box').css('display',visible ? '' : 'block');

});

Upvotes: 0

jack
jack

Reputation: 1317

Use jQuery toggle

jQuery(".btn").on('mouseover', function (e) {
    jQuery('.btn').toggle();
});

Upvotes: 0

Related Questions