.click() method, browser support
The only browser I have encountered that does not support .click()
is Safari. Safari supports .click()
on buttons (e.g. <input type="button" />
) but not on other elements such as anchor elements (e.g. <a href="#">Click Me</a>
).
For Safari, you have to use a workaround:
function click_by_id(your_id)
{
var element = document.getElementById(your_id);
if(element.click)
element.click();
else if(document.createEvent)
{
var eventObj = document.createEvent('MouseEvents');
eventObj.initEvent('click',true,true);
element.dispatchEvent(eventObj);
}
}
Using the above function, you can support 90%+ of browsers.
Tested in IE7-10, Firefox, Chrome, Safari.