Talk:Generate Click Events: Difference between revisions
Created page with '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, t…' |
Freeloader (talk | contribs) No edit summary |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
at the end: | at the end: | ||
> Assume that the el variable points to some element which we want to "click on": | <blockquote> | ||
> | Assume that the el variable points to some element which we want to "click on": | ||
<pre> | |||
var evt = document.createEvent("HTMLEvents"); | |||
evt.initEvent("click", true, true); | |||
link.dispatchEvent(evt); | |||
</pre> | |||
</blockquote> | |||
there is no "el variable", is "link" the right reference??? | 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. [[User:Arantius|Arantius]] 16:30, 1 June 2010 (UTC) | |||
---- | |||
In [http://wiki.greasespot.net/index.php?title=Generate_Click_Events&diff=6415&oldid=6397 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. | |||
<pre class='sample'> | |||
var evt = document.createEvent("MouseEvents"); | |||
evt.initEvent("click", true, true); | |||
el.dispatchEvent(evt); | |||
</pre> | |||
[[User:Kwah|Kwah]] 16:19, 23 June 2011 (EDT) | |||
---- | |||
Is there a particular reason why this section doesn't mention simply calling `[http://www.w3schools.com/jsref/met_html_click.asp element.click()]` ? AFAIK, this works in both cases (either when onclick attribute is defined or with the listener). [[User:Freeloader|Freeloader]] ([[User talk:Freeloader|talk]]) 20:57, 4 December 2012 (EST) | |||
---- |
Latest revision as of 01:57, 5 December 2012
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)