How can I convert jquery's on function to vanilla javascript?
Here is my jquery code.
$(document).on("click", ".eye", function () {
if ($(this).hasClass('on')) {
$(this).removeClass('on');
} else {
$(this).addClass('on')
}
});
I want to convert this function to vanilla javascript.
When I run document.querySlector('.eye') nothing is written to console.log. Because this object is dynamically created by javascript. So, I had no choice but to use jquery.
I was wondering how I can replace the above jquery with vanilla javascript.
Best Regards!