The main difference is already answered by @Mukesh. I will try to add one more thing.
When you click (or any other event) on an element (e.g. div or ) in the html document, this click event extends to the parent elements of this element. So, if you have a structure like this:
<div> <table> <tr> <td> <button>Click Me</button> </td> </tr> </table> </dvi>
and you click on the button, this click will apply to td, then to tr, then to the table, and then, finally, to the document itself.
Now let's say that you registered a click event on the document ( $ document.on ('click', ...) ), as well as on the button ( $ (button. On ('click', ...)) ), both of which perform several different actions. Then, if you click on the button, the corresponding button action will be performed, and the corresponding $ (document) action will be performed.
To prevent a button from being clicked for distribution on the document itself, you need to take action on the button click handler (for example, stopPropagation, etc.).
source share