I'm trying to simulate a click on an anchor tag using jQuery. I've been digging around StackOverflow and Google for a while and haven't found anything that works on all of the browsers I'm testing. So far, I've found this:
$(document).ready(function() {
$.fn.fireEvent = function(eventType) {
return this.each(function() {
if (document.createEvent) {
var event = document.createEvent("HTMLEvents");
event.initEvent(eventType, true, true);
return !this.dispatchEvent(event);
} else {
var event = document.createEventObject();
return this.fireEvent("on" + eventType, event)
}
});
};
$('a').fireEvent('click');
});
This will fire a click event in Safari, but not FireFox or the version of IE I tested. So, oh mighty minds of SO, what am I doing wrong? Any guidance would be greatly appreciated.