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

Event Handling with jQuery

Basic Events

  • .click(): Triggered when an element is clicked.
  • .hover(): Triggered when the mouse enters and leaves an element.
  • .dblclick(): Triggered on a double click.
JavaScript
$("#button").click(function () {
  alert("Button clicked!");
});

$("#box").hover(
  function () {
    $(this).css("background-color", "lightblue");
  },
  function () {
    $(this).css("background-color", "white");
  }
);

$("#button").dblclick(function () {
  $(this).text("Double-clicked!");
});

Using .on() to Handle Events

  • .on(): Used to bind events dynamically to existing or future elements.
JavaScript
$(document).on("click", ".dynamic-button", function () {
  alert("Dynamic button clicked!");
});