faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 14 people (57%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

how to trap all click events without specifying an event individually for each clik(button or tab

Apr 8th, 2008 18:19
ha mo, Dave Clark, Ajith Markose,


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ajith,
     I would need to know more about exactly what you're trying to 
accomplish in order to give you a definitive answer.  However, most 
browsers support event bubbling -- meaning, an event triggered on a 
child element will bubble up to the parent element, and so on, until 
the document element is reached.  Then, the event object includes a 
pointer to the original element which triggered the event.  So, try 
this as a starting point for your own research:
function TrapEvent(e)
{
  if (e) {
    alert('"'+ e.type +'" detected on '+ e.target.tagName +' 
element.');
  } else {
    alert('"'+ window.event.type +'" detected on '+ 
window.event.srcElement.tagName +' element.');
  }
  return true;
}
document.onclick = TrapEvent;
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com