Course Content
AJAX and jQuery Plugins
Learn how to use AJAX and plugins with jQuery to create dynamic and interactive web applications.
0/3
JQuery
About Lesson

Preventing Default and Propagation

  • .preventDefault(): Prevents the default action of an element (e.g., following a link).
  • .stopPropagation(): Stops the event from bubbling up to parent elements.
JavaScript
$("a").click(function (e) {
  e.preventDefault();
  alert("Default action prevented!");
});

$(".child").click(function (e) {
  e.stopPropagation();
  alert("Child clicked without propagating to parent!");
});