I use both methods when I want to finish handling the event. Something like the comsume() method in Swing. And always put the challenges of these methods together. Is there a difference between preventDefault() and stopPropagation() ?

The documentation says that

stopPropagation

Stops the propagation of a base native event.

preventDefault

Prevents the default action of a base native event.

Something like this. But it does not bring clarity.

    2 answers 2

    preventDefault denies the default behavior of an item. For example, clicking on the submit button will submit the form, and preventDeafult will stop it. Clicking a link redirects to another page $ ('a'). PreventDefault (); ban this action. The link will simply become an active underlined area.
    stopPropagation prohibits the transmission of events from the child to the parent, that is, if we clicked on the nested diva, its parent "will not feel" this click.

    Ideas examples of use. preventDefault: It's simple. Ajax links. stopPropagation: for example, buttons on top of the image. If we click on the picture, the next one is turned on; if by buttons - some other action, say, a magnifying glass.

    PS everything is not limited to clicks;)

      Well, I can’t say anything about preventDefault , and this method doesn’t let the base functions work on preventDefault , for example, if you want to hang up a handler on some link, then you need to set this up so that the computer doesn’t go over the link and executed your code. Something like this.