I'm trying to make javascript auto click on a href link to show more data on the same page.
The Link has a javascript:void(0)
Code block:
document.querySelector("#showMoreHistory256 > a").click();
<div id="showMoreHistory256" class="showMoreReplies block" onclick="ecEvent.moreHistory(256, this, 0)
,lk,m"><a href="javascript:void(0);">Show more</a></div>
But I get the result Undefined in the console instead of the execution of the function "show more".
Is the querySelector or the .click() the wrong command for this?
Try like this and you will not get errors:
var ecEvent = {
moreHistory: function (num,context,depth)
{
alert('The link was clicked programmatically');
}
};
var lk = false, m = false;
document.querySelector("#showMoreHistory256 > a").click();
<div id="showMoreHistory256" class="showMoreReplies block" onclick="ecEvent.moreHistory(256, this, 0)
,lk,m"><a href="javascript:void(0);">Show more</a></div>