You can keep a counter that you increment in the click event handler.
let counter = 0;
document.querySelector('img').addEventListener('click', e => {
++counter;
if (counter === 5) { //change to any number you want
//do something
console.log('clicked 5 times');
}
});
<img src="https://www.w3schools.com/images/html5.gif" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…