What's the difference between event.stopPropagation and event.preventDefault?

后端 未结 7 1286
余生分开走
余生分开走 2020-11-22 00:52

They seem to be doing the same thing...
Is one modern and one old? Or are they supported by different browsers?

When I handle events myself (without framework) I

7条回答
  •  无人及你
    2020-11-22 01:27

    event.preventDefault(); Stops the default action of an element from happening.

    event.stopPropagation(); Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

    For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.

提交回复
热议问题