Reputation: 820
I know this question has been asked many times before and there are countless answers for it but the issue that I have is that I have no idea why I cannot autoclick a link on page load!
I have used the same process over 20 times before without any issue but now it doesn't work...
Here is a fiddle with the issue: https://jsfiddle.net/1xy0f291/
and this is my code:
$(document).ready(function(){
alert('hello');
$('#pop').trigger('click');
$('#pop').click();
});
anyone has any idea why this is happening?
Upvotes: 3
Views: 117
Reputation: 376
try this :
document.getElementById('pop').click()
updated fiddle : Fiddle
Upvotes: 1
Reputation: 22031
Add some small code fix, use eq():
$('#pop').click(); -> $('#pop').eq(0).click();
$('#pop').trigger('click'); -> $('#pop').eq(0).trigger('click');
Upvotes: 0
Reputation: 67207
Basically $().click()
will invoke the click event handler bound with it. Not the natural click.
For invoking the natural click you have to access the plain node object and call its click()
function,
$('#pop')[0].click();
Upvotes: 9