I’m trying to create an .on() method using events-map. I want to change this: $("ul").on("click", "li", function() {...}); to something like this:
$("ul").on({
click: function() {...},
mouseenter: function() {...},
mouseleave: function() {...}
});
Where do I put the selector “li” in the events-map?
You just put it as the second argument as usual:
From the docs:
Parameters enclosed in [] are optional. So, if you do not pass a selector, the events are bound to the elements in the jQuery object, in this case all
ul-elements on the page. If, however, the selector is provided, then the elements in the jQuery objects handles event delegation for the set of elements matched by the selector. I.e when an event occurs on an element matching the selector that is a descendant of the element in the jQuery object, that event handler will be called once the event has bubbled its way up to the parent. Note that this means that if the event propagation is canceled before it reaches the parent, the event handler will not be called.