Your Search Results

    event.target Redirect 1

    « DOM Reference

    Summary

    This property of event objects is the object the event was dispatched on. It is different than event.currentTarget when the event handler is called in bubbling or capturing phase of the event.

    Syntax

    event.target

    Example

    The event.target property can be used in order to implement event delegation.

    // Assuming there is a 'list' variable containing an instance of an HTML ul element.
    function hide(e){
      // Unless list items are separated by a margin, e.target should be different than e.currentTarget
      e.target.style.visibility = 'hidden';
    }
    
    list.addEventListener('click', hide, false);
    
    // If some element (<li> element or a link within an <li> element for instance) is clicked, it will disappear.
    // It only requires a single listener to do that
    

    Browser compatibility

    On IE6-8, the event model is different. Event listeners are attached with the non-standard element.attachEvent method. In this model, the event object is not passed as an argument to the event handler function but is the window.event object. This object has an srcElement property which has the same semantics than event.target.

    Specification

    DOM Level 2 Events: Event.target

    See also

    Comparison of Event Targets

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,