hide element when user clicks outside the element
$.fn.hideOnClickOutside = function () {
target = $(this);
$(document).on('click', function() {
target.hide();
});
target.click( function(event) {
event.stopPropagation();
});
return target;
}