Replace jquery $("body").on for child elements with Vanilla Script

how is it possible to replace this jQuery with Vanilla:

$( document ).ready(function() {
    $('body').on('click', '.f_click', function (e) {
        e.preventDefault();
        alert("TEST");
    });
});

My first try was:

document.addEventListener('click', function (e) {
    console.log(e.target);
    if (e.target.classList.contains('f_bme_start')) {
        alert('open Search!');
        return false;
    }
}, false);

this works, but not on child elements.
Has somebody an idea how to solve this?

I want to replace all my jQuery code because of slow performance…..
THANKS

91 thoughts on “Replace jquery $("body").on for child elements with Vanilla Script”

Leave a Comment