I have a jQuery selectable lislt and I want to deselect the items when clicked outside the list.
Initially I used : $('body').click(...)
which worked but it detects click on all the elements inside the body. I want to detect it except for clickable elements such as tags like a
, button
, input
, select
etc.
So I modified my code as follows:
$("body").click(function (event) {
var tagname = event.target.tagName.toLowerCase();
if (tagname != "a" && tagname != "button" && tagname != "input") {
$('#selectable .ui-selected').removeClass('ui-selected');
}
});
which does not look like an elegant way to do it. And it would even miss certain elements if not defined.
Is there a better way to do this? A way to detect empty spaces in body with no text or click functions attached?