here is an example that works, first create an element, then addEventListener
// ==UserScript== // @name GM addEventListener Function Test // @namespace ewwink.com // @description GM addEventListener Function Test // @include http://* // ==/UserScript== document.body.innerHTML+='<input type="image" id="alertMeID" onclick="do_this()" style="position:fixed;top:0;left:0" src="http://i55.tinypic.com/2nly5wz.gif" />'; document.getElementById('alertMeID').addEventListener('click', do_this, false); function do_this(){ alert('hello World!, today is: '+new Date()) }
source share