Javascript and jQuery events examples and cheatsheet

Javascript and jQuery events examples and cheatsheet

Last updated:

AJAX get example

$.get(
    location.href,
    data,
    function(data) {
        //code
});

AJAX post example

$.post(
    location.href,
    data,
    function(data) {
        //code
});

get the ID of the element that triggered an event

$(aSelector).keyup(function(event){
    console.log(event.srcElement.id);
});

or, using jQuery

$(aSelector).keyup(function(event){
    $(this).prop('id');
});

Dialogue & Discussion