For example, we have such an html structure.
<ul>
<li>
item 1
<button class="btn-edit"><i class="fas fa-pencil"></i></button>
</li>
<li>
item 3
<button class="btn-edit"><i class="fas fa-pencil"></i></button>
</li>
<li>
item 3
<button class="btn-edit"><i class="fas fa-pencil"></i></button>
</li>
</ul>
Note that there is an i tag inside the button.
If you want to capture exactly the right item for the Click event, you need a function like the one below.
function delegateClick(selector, callback){
let selectorItems = document.querySelectorAll(selector);
document.addEventListener('click', function(e){
let clickedItems = e.path;
for(let clickedItem of clickedItems){
for(let selectorItem of selectorItems){
if(clickedItem === selectorItem){
callback(clickedItem);
}
}
}
});
}
This offers a very similar use to jquery.
delegateClick('.btn-edit', (elm) => {
//access the clicked DOM element
elm;
});