Reputation: 937
I want to call click() for a given id inside setInterval
setInterval(function(){
document.getElementById('test').click();
}, 10);
This click() is working for a tag by clicking from another tag. But not working when I am just calling it in setInterval or even calling the same line in script. Any way I can achieve this ?
Jquery click is also not working neither any trigger call.
setInterval(function(){
$('#test').trigger('click');
}, 10);
Here is the complete code for testing:-
<html>
<body>
<p>Select a File to Load:</p>
<input id="inputFileToLoad" type="file" onchange="loadImageFileAsURL();" />
<a id="testy" href="" onclick="document.getElementById('inputFileToLoad').click(); return false">Upload</a>
<br />
<script type='text/javascript'>
function loadImageFileAsURL()
{
alert("Its a Test");
}
setTimeout(function(){
document.getElementById('testy').click();
}, 1000);
</script>
</body>
</html>
Upvotes: 0
Views: 1506
Reputation: 11750
EDIT (check console)
setInterval(function(){
$('#test').trigger('click');
}, 10);
$(document).on('click', '#test', function() {
console.log('clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">test</div>
Upvotes: 1