Pages

Tuesday, January 19, 2010

Finding the type on HTML Element which was clicked using Javascript

/*****************************************************************
@Purpose    :    To find the Type of HTML Element from which the a event is fired
@Created:    19-Jan-2009
@Author:    Karthikeyan A
@Name:    myClickListener
@Param:    e - refers to event object
@Return:    A- for anchor tags
                 INPUT- for <input ..../> tags
                 TEXTAREA- for <TextArea.../>tags etc...
*****************************************************************/
function myClickListener(e)    {
    //variable to store the name of the element on which user clicks
    var eventIsFiredFromElement;
    if(document.all)    {        // IE
        eventIsFiredFromElement = e.srcElement;
    }    else    {        // Firefox
        eventIsFiredFromElement = e.target;
    }

    //alert("Event is fired from element : " + eventIsFiredFromElement.tagName);
    return eventIsFiredFromElement.tagName;
}

No comments:

Post a Comment