jQuery - on example

In this blog, I will create a basic example for the jQuery's on method. On method is a replacement for bind, delegate and live method.
On method allows us to attach event handler function for one or more events. On method can be used in scenarios where the elements are going to be added dynamically. For ex, lets say that we want to attach an event to the click of all 'p' tags. If we use $("p").click(some func), this will work fine for existing functions. But if we have a button which adds 'p' tags, those tags wont have the click handler. In such cases we can use the on method as shown in the example.

No comments: