peiman F.
peiman F.

Reputation: 1658

hide on window and other element click

I have a button its id is tools onclick it show a menu with some links and with click on other places of the page this menu will be hidden.

Every think work well but the menu don't hide when I click on the buttons (#up,#del,#tools)

$('#tools').click(function(){
    var ofset = $(this).offset();
    $('#moreMenu').css({'top':(ofset.top+35),'left':ofset.left,'display':'',});
    return false;
});

$(window).click(function(){$('#moreMenu').hide();});

    <div id='moreMenu' style='width:250px;background-color:#f0f0f0;border:2px solid gray;height:100px;position:absolute;display:none;'>some menu</div>

<button id='up' title='up'  >‍<img src='../images/beta/up.png'></button>

<button id='del' title='del'  >‍<img src='../images/beta/delete.png'></button>

<button id='tools' title='tools' style='width:70px;' >‍<img src='../images/beta/tools.png' style='margin-right:30%;'></button>

How can be hide on every elements!?

Upvotes: 0

Views: 1903

Answers (2)

Md Ashaduzzaman
Md Ashaduzzaman

Reputation: 4038

Just use the click event on html. It'll let you hide the div when you click anywhere inside the page.

$("html").click(function(){$('#moreMenu').hide();});

OR,

$(document).click(function(){$('#moreMenu').hide();});   

A Thread Reference: $(window).click(..); not working in IE

Demo

Upvotes: 1

Jade
Jade

Reputation: 649

That's because you need to add javascript to hide the menu when the buttons are pressed.

$("button").click(function(){$('#moreMenu').hide();});

Upvotes: 0

Related Questions