Friday, 20 July 2012

How to find event target using jQuery?

This can be done using property. It returns a reference to the DOM element that initiated the event. t is often useful to compare to this in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.

Example: Implements a simple event delegation: The click handler is added to an unordered list, and the children of its li children are hidden. Clicking one of the li children toggles (see toggle()) their children.

<!DOCTYPE html>
  <script src=""></script>
  <li>item 1
      <li>sub item 1-a</li>
      <li>sub item 1-b</li>
  <li>item 2
      <li>sub item 2-a</li>
      <li>sub item 2-b</li>


function handler(event) {

var $target = $(;

  if( $"li") ) {




No comments:

Post a Comment