Difference between document.onclick() and click() function

There is no onclick event in jquery but there is .on eventinterviewer asks sometime

.click(handler):  Bind an event handler to the “click” JavaScript event, or trigger that event on an element.

.on( events [, selector ] [, data ], handler ) : Attach an event handler function for one or more events to the selected element. they can process events from descendant elements that are added to the document at a later time.

So if you are adding an element on page dynamically and want to fire an event use .on .

Leave a comment