0

I am using the following code to toggle (show/hide) a drawer: http://outof.me/navigation-drawer-pattern-with-topcoat-css-library/

slideMenuButton.onclick = function (e) {
    var cl = document.body.classList;
    if (cl.contains('left-nav')) {
        cl.remove('left-nav');
    } else {
        cl.add('left-nav');
    }
};

Works fine. Now, I would like the drawer to close whenever anything outside the drawer is clicked. Is there a recommended way how to do this?

pruefsumme
  • 341
  • 3
  • 16

1 Answers1

0

The solution would be:

$("body").on("click",function(e) {
    var cl = document.body.classList;
    if (cl.contains('left-nav')) {
        cl.remove('left-nav');
    }
}

(Works for me.)

pruefsumme
  • 341
  • 3
  • 16