You can resort to the concept of event delegation.
$(function() {
$(document).on('click', function(e) {
if (e.target.id === 'div1') {
alert('Div Clicked !!');
} else {
$('#div1').hide();
}
})
});
Check FIDDLE
I did not understand what you meant by integrating with the other part.. This is the basic idea..