jQuery: how to check if event exists on element


Get all events registered by jQuery:

$._data(element, "events")

Example:

$._data(document, "events")

Get all events registered by jQuery

Check if event exists on element:

function checkEvent(element, evntType, handler) {
  var elemEvents = $._data(element, "events");

  var evts = elemEvents[evntType];
  var check = false;
  for (var i = 0; i < evts.length; i++) {

    if (evts[i].handler == handler) {
      check = true;
      break;
    }

  }

  return check;
}

Example:

checkEvent(document,'fscreenclose',__s)

Check if event exists on element

Leave a Reply