Question
What is the .on()
method in jQuery?
Answer
The .on()
method in jQuery attaches an event handler, which is the event listener plus the callback function, to the selected element(s).
What is the .on()
method in jQuery?
The .on()
method in jQuery attaches an event handler, which is the event listener plus the callback function, to the selected element(s).
Thanks for your explanations, but i have seen on many site like w3school they don’t use .on() method in their example they directly attach even listen to the element selector like this -
$(".btn2").click(function(){
$(“p”).slideToggle();
});
So which way is better?
Yoy might want to read this SO thread: