I want to create a page with 2 buttons, 'STAY' and 'Leave'. There is an iFrame underneath the buttons. When the page loads for the first time, the iFrame starts refreshing automatically after 10 secs. When the user hits STAY button, it will stop refreshing. After that if he hits LEAVE button the iFrame will again start refreshing after 10 secs. I'm using this code:
$(document).ready(function() {
var refreshIntervalId = setInterval( "update()", 10000 );
$('#leave').click(function () {
var refreshIntervalId = setInterval( "update()", 10000 );;
})
$('#stay').click(function () {
clearInterval(refreshIntervalId);
})
});
function update(){
var url = "load.php";
$('iframe#ifrm').attr('src', url);
}
<div id="bar">
<div class= "button" id="stay">
<a>Stay</a>
</div>
<div class= "button" id="leave">
<a>Leave</a>
</div>
</div>
but it doesn't work, am I using clearInterval in the wrong way?