arrow_back
Back

jQuery events: on, off, delegation, and namespaced handlers

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

open_in_new Good jQuery manuals .

keydown

Every time when a key pressed:

$("body").keydown(function (event) {
    console.log(event.keyCode);
});

click

When a user clicks on an element in a browser, click event occurs. We can subscribe to the event and set an event handler.

var clickHandler = function (event) {
    console.log("Click! " + event.pageX + " " + event.pageY);
};

$("#some-button").click(clickHandler);

mousemove

The onmousemove event occurs when the pointer is moving while it is over an element.

Example:

$("html").mousemove(function (event) {
    $("#some-element").offset({
        left: event.pageX,
        top: event.pageY
    });
});

Event object

Properties:

  • offsetX
  • offsetY
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

jQuery AJAX: $.ajax, shorthand methods, and JSON

arrow_forward