What is the (vanilla) javascript equivalent of
$(document).on('click', '#myElement', function() {/*do something*/});
Is there something shorter than
document.addEventListener('click', function(e){
if (e.target.id=='myElement'){
/*do something*/
}
});
I'm wondering if the latter is heavy handed as it will proceed to process all clicks, but the jquery version only proceeds with clicks on the required element, so perhaps there is a more elegant javascript version than this?
I want the handler at document level to deal with subsequently dynamically added elements.