I\'d like to hide a div when user click anywhere on the page outside of that div. How can I do that using raw javascript or jQuery?
Attach a click event to the document to hide the div:
$(document).click(function(e) { $('#somediv').hide(); });
Attach a click event to the div to stop clicks on it from propagating to the document:
$('#somediv').click(function(e) { e.stopPropagation(); });