Posted By

MMDeveloper on 09/18/08


Tagged

javascript event trigger


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

michaJlS
iTony


Manually Trigger Element Event Via Code


 / Published in: JavaScript
 

URL: http://www.mechanicmatt.com

  1. <a href="#" onclick="alert('onclick executed');" id="testLink">some link</a>
  2.  
  3. <script type="text/javascript">
  4. <!--
  5. function fireEvent(element, eventName) {
  6. evt = document.getElementById(element)[eventName];
  7.  
  8. if (typeof(evt) == "function") {
  9. document.getElementById(element)[eventName]();
  10. } else {}
  11. }
  12.  
  13.  
  14. fireEvent("testLink", "onclick");
  15. -->
  16. </script>

Report this snippet  

You need to login to post a comment.