I have a setInterval
running which checks for existence of an element with a certain class. If it finds it then it binds the click event to that element and clears the interval.
Inside this click event I want to restart the same setInterval
again. This I am not able to achieve.
I have tried this code but it doesnt restart the setInterval
outside document.ready (global)
var interval;
var onInterval;
inside document.ready
onInterval = function () {
//check if an element with this class exists
if ($('.lpInviteChatHrefClose').length) {
$(".lpInviteChatHrefClose").click(function () {
outbound_reject_omniture_setting(this);
//This should restart the interval but it doesnt
//Also tried the following but in vain
//clearInterval(interval);
//delete window.interval;
//delete interval;
//interval = null;
interval = setInterval(onInterval, 1000);
});
clearInterval(interval);
}
};
interval = setInterval(onInterval, 1000);
Also I have tried the following but it is also not working. It is not binding the first click itself I dont know why. There is no error in the console.
$(document).on('click', '.lpInviteChatHrefClose', function(){
// your code here...
});
Please help!
Thanks in advance.