Skip to content

Instantly share code, notes, and snippets.

@logeshpaul
Created May 7, 2014 10:51
Show Gist options
  • Select an option

  • Save logeshpaul/7ff4283744c3d0b05ad4 to your computer and use it in GitHub Desktop.

Select an option

Save logeshpaul/7ff4283744c3d0b05ad4 to your computer and use it in GitHub Desktop.

Revisions

  1. logeshpaul created this gist May 7, 2014.
    13 changes: 13 additions & 0 deletions outside.click.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // 'touchstart' helps trigger the event in touch devices
    $(document).on('click touchstart', function(e){
    if ($(e.target).closest("#menuscontainer").length == 0) {
    // .closest can help you determine if the element
    // or one of its ancestors is #menuscontainer
    console.log("hide");
    }
    });

    $('#menuscontainer').on('click', function(e){
    e.stopPropagation();
    e.preventDefault();
    }