DOM Level 0 "Fire Event"


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Method to fire DOM0 events such as onblur, onfocus, onchange
  2. function fireEvent(element,event){
  3. if(document.createEvent){
  4. var evt = document.createEvent("HTMLEvents");
  5. evt.initEvent(event,true,true);
  6. return !element.dispatchEvent(evt);
  7. } else if(document.createEventObject) {
  8. var evt = document.createEventObject();
  9. return element.fireEvent('on'+event,evt);
  10. }
  11. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.