Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  73] [ 4]  / answers: 1 / hits: 127604  / 15 Years ago, thu, april 30, 2009, 12:00:00

In IE, I can just call element.click() from JavaScript - how do I accomplish the same task in Firefox? Ideally I'd like to have some JavaScript that would work equally well cross-browser, but if necessary I'll have different per-browser JavaScript for this.


More From » dom

 Answers
10

The document.createEvent documentation says that The createEvent method is deprecated. Use event constructors instead.



So you should use this method instead:



var clickEvent = new MouseEvent(click, {
view: window,
bubbles: true,
cancelable: false
});


and fire it on an element like this:



element.dispatchEvent(clickEvent);


as shown here.


[#99619] Saturday, April 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;