Jquery Events With Example

Jquery Events allows to Ttrigger or Attach a Function for the selected elements.

September 14, 2020

1) Click Event

$("input[type='button']").click(function () {
    alert("Button Clicked");
    // Your Code
});
 
$("a").click(function (e) {
    e.preventDefault();
    alert("Anchor Link Clicked");
    // Your Code
});

You can define any html element to call it's click event

2) Bind Event (To Attach a defined event to the html element)

$("input[type='button']").bind("click"function () {
    alert("Button Clicked");
    // Your Code
});
 
$("a").bind("mouseover"function (e) {
    e.preventDefault();
    alert("Mouseover function called");
    // Your Code
});

You can define any event to bind on any html elment

3) On Event (To Attach a defined event to the Dynamically (on Run Time) created html element)

$(document).on("click""input[type='button']"function () {
    alert("Button Clicked");
    // Your Code
});
 
$(document).on("mouseover""a"function (e) {
    e.preventDefault();
    alert("Mouseover function called");
    // Your Code
});

4) Change Event (To Attach a defined event when an <input> field is changed)

$("input[type='text']").change(function () {
    alert("Text has been changed.");
    // Your Code
});

Post Comments(0)

Leave a reply

Will not be displayed in comment box .

Loading...