Im trying to create an overlay on click of a button and then removing it when the user clicks outside the overlay. In my example the target returns a length of "0" when the overlay is clicked and I can't figure out why when this method works with other examples I've used it with. Any idea?
Here's the js
$(document).ready(function() {
$(document).on("click",".pop", function() {
if ($('#search-overlay').length === 0) {
$('body').append('<div id="search-overlay"></div>');
}
});
$(document).on("mouseup", function(e) {
var container = $("#search-overlay");
if (container.has(e.target).length === 0) {
alert(container.has(e.target).length);
container.remove();
}
});
});
And the link where you see it in action http://jsfiddle.net/CwrAh/