I have a table that display users in a database. When a user clicks on the usergroup a dropdown div will appear with a selection of available usergroups. I would like that div to hide again when the user clicks outside that div
I’ve done a bit of messing around, and there may be an easier way to do this but here’s what I’ve come up with:
In your jQuery file do something like this in your $(document).ready() function:
$(document).click(function(e){
var elem = $(e.target).attr('id'); //this should give you the clicked element's id attribute
if(elem !== 'ugselect-10003'){
$('#ugselect-10003').slideUp('slow'); //or however you want to hide it
}
});
I haven’t tested all of that but I think the idea is there if you want to mess around with it. I did try the first part (checking the clicked element’s id) and that worked for me.
Thanks for the reply. I’ve actually decided to take a different route. Instead of closing when you click outside, I’ve decided to include a close “X” in the upper right corner which, when clicked, triggers the dive to hide