2

I have created an overlay which covers the entire page, I am looking for a way to either click on the body to close the overlay and/or using the escape key:

  <div id="navigationPop" class="myContent">
    <ul>
      <li>Search</li>
    </ul>
  </div>

function toggleDiv(divId) {
    $("#"+divId).fadeToggle();
}
coder123
  • 183
  • 1
  • 3
  • 14

1 Answers1

2

escape:

$(document).keyup(function(e) {
  if (e.keyCode == 27) { <DO YOUR WORK HERE> }   // esc
});

How to detect escape key press with JavaScript or jQuery?

Click outside overlay:

$('html').click(function() {
    //Hide the menus if visible
});

$('#menucontainer').click(function(event){
    event.stopPropagation();
});

How do I detect a click outside an element?

Community
  • 1
  • 1
Tarwirdur Turon
  • 751
  • 5
  • 17
  • Hey, So where in the first example it says do your work here....is there I would input my bit of script? I tried but it disabled the trigger – coder123 Jan 28 '15 at 22:13