Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  120] [ 1]  / answers: 1 / hits: 20677  / 11 Years ago, mon, may 13, 2013, 12:00:00

I am looking for a function in javascript which clicks on every element (links, buttons,...) on my page. All elements should be disabled by default. I am using this for my testing environment in Selenium to check whether all elements on my page are deactivated.


More From » javascript

 Answers
57

At first, get all elements on your page:



var elements = document.getElementsByTagName(*);


Now that you get them, make a mouse-event, make a loop and apply the event on every element:



var clickEvent  = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
for (var i=0; i < elements.length; i++)
{
elements[i].dispatchEvent (clickEvent);
}

[#78269] Saturday, May 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;