0

I have a little script that makes a little bottom mounted "quick menu" close when the user clicks anywhere on the page. I used 'body' as the selector. However, I don't want it to close when the user clicks inside the menu (which is inside the div foot).

I've tried putting the selector as '*' then using .not('.foot body'), however that doesn't seem to solve anything. What are the chances I've actually typed the code wrong?

$(document).ready(function(){
  $('*').not('.foot body').click(function(){
      if($('.foot').hasClass('slide-up')) {
        $('.foot').addClass('slide-down', 1200, "easeOutQuad");
        $('.foot').removeClass('slide-up'); 
        $('.UP').text('Up ↑');
      } else {
      }
  });
});

Edit: It does work fine, and closes as it should, it's just the fact I don't want .foot to be able to close it

MyNameWouldGoHere
  • 145
  • 1
  • 2
  • 13
  • 1
    You're saying it shouldn't apply to `body` elements inside `.foot`. To specify both of them, comma separate them. Seems to me you only want to exclude `.foot`, so do `$('*').not('.foot').click()` – scrowler Aug 14 '14 at 01:39
  • That's the strange thing, it still seems to happen when doing it the way you suggested. It's not a major issue, but it's just bugging me the fact it doesn't work! I tried to create a JSFiddle, but it wouldn't work properly so I had to give up with it – MyNameWouldGoHere Aug 14 '14 at 02:03
  • Ok, the other option is you bind to the entire document and check if the target you clicked has the foot class: `$(document).on('click', '*', function() { if($(this).hasClass('foot')) return false; // put the rest of your code here });` – scrowler Aug 14 '14 at 02:06
  • Ah, yes, that's brilliant! Works perfectly, thank you – MyNameWouldGoHere Aug 14 '14 at 02:13
  • ^ Tried that, never got it to work so had to create a new question – MyNameWouldGoHere Aug 14 '14 at 02:32

0 Answers0