We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

noah on 07/20/07


Tagged

wrapper event crossbrowser browser DOM click dhtml ui trigger tools chrome bubble propagation ecom clicking container simulate onebigeventhandler onebigone encapsulation


Versions (?)


click on an element across browsers


Published in: JavaScript 


If you have assigned an event handler to a container, you might want to remotely trigger it as if a child of the container had been clicked. That is, you might want to manually set the target of the 'event' object that is passed to the event handler on the container. This helps to keep the number of event handlers down.

  1. //assuming that 'menu' has an appropriate onclick handler:
  2. function simulateClick( itemToClick, menu) {
  3. if ( ! itemToClick.click ) {
  4. //== Non-IE:
  5. menu.onclick({target: itemToClick});
  6. } else {
  7. //== IE:
  8. itemToClick.click()
  9. }
  10. }

Report this snippet 

You need to login to post a comment.