Talk:Generate Click Events

From GreaseSpot Wiki
Jump to navigationJump to search

at the end:

Assume that the el variable points to some element which we want to "click on":

var evt = document.createEvent("HTMLEvents");
evt.initEvent("click", true, true);
link.dispatchEvent(evt);

there is no "el variable", is "link" the right reference??? I don't want to change anything unless I'm sure that I'm right.

Good catch. Fixed. Arantius 16:30, 1 June 2010 (UTC)

In this edit "HTMLEvents" was changed to "MouseEvents" see sample below.

Based on a brief reading of Mozilla Developers Wiki, if the example were to be changed to use "MouseEvents", initEvent should also be edited to be initMouseEvent. Long story short it should be one or the other (HTMLEvents & initEvent or MouseEvents & initMouseEvent) but not a mix of both and I do not know enough about this to be able to decide either way. Please advise whether to simply revert or edit to add initMouseEvent.

var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
el.dispatchEvent(evt);

Kwah 16:19, 23 June 2011 (EDT)


Is there a particular reason why this section doesn't mention simply calling `element.click()` ? AFAIK, this works in both cases (either when onclick attribute is defined or with the listener). Freeloader (talk) 20:57, 4 December 2012 (EST)