stop setInterval on mouseleave
I'm trying to run a function every 1/2sec using setInterval on mouseenter & stop it on mouseleave.
- function checkRExist(xInter) {
- if ($('.g-recaptcha-bubble-arrow').length > 0) {
- console.log('reCaptcha Exists');
- clearInterval(xInter);
- }
- }
- function stopInter(xInter) {clearInterval(xInter)}
- $('.g-recaptcha').on('mouseenter', function() {
- console.log('Mouse Enter');
- var xInter = setInterval(checkRExist, 500);
- });
- $('.g-recaptcha').on('mouseleave', function(xInter) {
- console.log('Mouse Leave');
- stopInter(xInter);
- });
The mouse enter console shows, and then reCaptcha exists console shows when clicking & then then the mouse leave shows, but then the reCaptcha exists starts all over again. Would like to stop it once a mouse leave occurs. What needs to be changed??