As I mentioned in the title, How can i rewrite this Jquery Code into Vanilla JS
Here's Jquery Code Example:
$(document).on('click', '.btn', function())
This is how VanillaJS snippet could look like
document.addEventListener('click', function (event) {
if (!event.target.matches('.btn')) return;
event.preventDefault();
// Your code
}, false);
or if You prefer to attach click handler to specific element
var clickMe = document.querySelector('.click-me');
clickMe.addEventListener('click', function (event) { // Dosomething... });
You can use the querySelector function which is similar to the $ in jQuery and add the desired listener using the addEventListener. If you want a list of all elements of the btn class you can use the querySelectorAll function.
See documentation here: