On a web page I have some text that I wish to blink under certain conditions (when counter is even) and not to otherwise
The problem is that once it starts blinking, it blinks all of the time. How can I stop it?
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
<title>Test blink</title>
</head>
<div id="wait-text"> </div>
<button onclick="updateText()">Click</button>
<script>
var counter = 0;
var wait_text = document.getElementById('wait-text');
function updateText() {
counter ++;
wait_text.innerHTML = `wait ${counter}`;
wait_text.className = '';
if (counter % 2 == 0) {
wait_text.innerHTML = `blink ${counter}`;
wait_text.className = 'blinking';
}
}
function blinker() {
let fadeout = 1500;
let fadein = 750;
$('.blinking').fadeOut(fadeout);
$('.blinking').fadeIn(fadein);
}
setInterval(blinker, 500);
</script>