I've an element in HTML, on clicking of which some processing happens. I'm trying to click that element using javascript.
First I tried
document.getElementById("id").click();
And it didn't work. Then I tried to dispatch click event like this
eventFire(document.getElementById("id"), 'click');
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
But this is also not working. Are any other alternatives there that I can try??
EDIT
Actually I've this webpage http://zzzscore.com/1to50/en/ in which there are blocks numbered from 1 to 25, and the processing happens when I click on "1".
So I'm writing a javascript function to click that automatically. The else part of the eventFire
function is getting executed, but the processing is not happening which occurs on regular click.
Also, from chrome dev tools, I found that the blocks are registered with onmousedown event, but passing 'mousedown' as parameter to my function also doesn't work. (In case of normal mouse click, the processing still starts when I release the mouse button only)
For instance, the HTML code for block is like this
<div style="opacity: 1;">
<span class="box" style="z-index:99"></span>
1
</div>
And I'm passing the "div" element as parameter "el" in my function