The below code works fine on IE7 but not in Safari(5.0.5). If possible, I want to avoid using jQuery. The goal is for this functionality to work on iPad but right now testing with desktop safari. Please let me know if you have any ideas on getting it to work both on IE and Safari.
<div id="test" ></div>
<script>
function attachCallback(node) {
node.onclick = function() {
alert("coming here");
} ;
}
var retrybutton = document.createElement("img");
retrybutton.src = "test.png";
retrybutton.alt = "retry";
retrybutton.setAttribute("id","retrybutton");
attachCallback( retrybutton ) ;
var a = document.getElementById("test");
a.appendChild(retrybutton);
// testing without using retrybutton
var test = document.getElementById("retrybutton");
test.click();
</script>
</body></html>
Update: Debating whether to go with "onmouseup" or something like below [Thanks Andres!! I'm not able to add comments]
if (Prototype.Browser.IE) {
document.getElementById("retrybutton").click();
} else { // from question link in comment
var event = document.createEvent("HTMLEvents");
event.initEvent("click", true, true);
document.getElementById('retrybutton').dispatchEvent(event);
}