I've read many SO answers on this but none of them is quite what I need. I have a div button which when clicked shows a div called #settingswindow. I would like to be able to close it when I click away.
The code below does that but the #settingswindow div also closes when I click on it, which is an undesirable effect.
// settings button
$(document).ready(function(){
$("#settings").click(function(event){
event.stopPropagation();
$("#settingswindow").toggle();
});});
$(function(){
$(document).click(function(){
$('#settingswindow').hide();
});
});
Thanks for your help.
Add this line:
$("#settingswindow").click(function(e){
e.stopPropagation();
});
http://jsfiddle.net/DerekL/N9cbk/
Create a function for $('#settingswindow').click(), then use event.stopPropagation() http://api.jquery.com/event.stoppropagation/ to stop event bubbling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With