If I understand you correctly, you can filter by selector. For instance:
$('body').on('click', 'a', function(){ ... });
This will bind the click event to all elements matching the selector a .
If you want to attach a click to all elements that do not match your popup, you can do something like:
$('body').on('click', ':not(#popup)', function(){
See jquery documentation for : not () and . on () for more information ...
source share