The problem may be that you are passing .not() to throw an exception
.not($("#mydiv").children())
At the moment you are passing a jQuery object, but from the documents , what is passed to .not() should be either a string selector, a DOM element or an array of DOM elements. Therefore, simply converting a jQuery object to an array of elements should work
$("#button").click(function(){ var myDiv = $("#mydiv").show(); $(document.body).not(myDiv.children().get()).one('click',function(e) { myDiv.hide(); }); return false; });
source share