Quantcast
Viewing latest article 9
Browse Latest Browse All 10

trigger JavaScript event click

Problem And Question

I have a hyperlink in my page. I am trying to automate a number of clicks on the hyperlink for testing purposes. Is there any way you can simulate 50 clicks on the hyperlink using JavaScript?

<a href="#" target="_blank" onclick="javascript:Test("Test");">MSDN</a>

I’m looking for onClick event trigger from the JavaScript.

Best Solution And Answer

Add an ID to your link

<a href="#" target="_blank" id="my-link" onclick="javascript:Test('Test');">MSDN</a>

and call it in your javascript code:

var l = document.getElementById('my-link');
for(var i=0; i<50; i++)
   l.onclick();

Viewing latest article 9
Browse Latest Browse All 10

Trending Articles