I'm trying to convert a jQuery event handler to pure javascript. There are loads of a particular selector on the page, so this was designed with only one event targeting document with that selector:
$(document).on("click", selectorString, function(event) {
// do stuff
});
Where selector
is a list of selectors as a string ".one, .two, .three
".
I'm struggling to replicate this without jQuery though:
document.addEventListener("click", function(event){
if (elementHasClass(event.target, selectorString) {
// do stuff
}
});
But this doesn't have the desired behaviour, as the listener is only on the document
element, rather than the selected element within the document. Can anyone help with this?