I'm trying to get a button to lose focus after 5 seconds using .Blur() but using setTimeout and setInterval aren't working with the code I'm using.
I'm using VideoJS to get the time in the video, and between 1 and 10 seconds, the button with ID of 'butt6' should change to focused which is working.
The issue I'm experiencing is unfocusing after 5 seconds.
In the code, I have got between 1 and 10 seconds, and I've got the setTimeout set to 5 seconds to test whether it was working but it isn't and am currently relying on an elseif .blur() to lose focus after the 10 seconds is up.
I've scoured the internet trying to find someone else who may have had a similar issue but everything I've tried so far either doesn't focus the button or doesn't un-focus at all.
Code is below:
var myPlayer = document.getElementById('my_video_1');
var myFunc = function(){
var whereYouAt = myPlayer.currentTime;
if (whereYouAt > 1 && whereYouAt <= 10){
var linkToFocus = document.getElementById('butt6');
linkToFocus.focus();
setTimeout(function(){ linktoFocus.blur(); }, 5000);
}
elseif (whereYouAt > 11){
linkToFocus.blur();
}
myPlayer.addEventListener('timeupdate',myFunc,false);
I believe the issue is that the
if
keep executing and focusing after thesetTimeout
. This should solve: