I'm trying to stop a loop after bt_stop click. But it is not working fine. clearInterval is not woking after the stop button is clicked.
<div id="abc">
<input id="bt_go" type="button" value="go" />
<input id="bt_stop" type="button" value="stop" />
<div id="output"></div>
</div>
<script>
$('#bt_stop').click(function () {
Get_close('','user1');//enter code here
})
$('#bt_go').click(function () {
Get_close(''#output'',user1');
});
function Get_close(id, output) {
if (id!= '') {
id = setInterval(function () {
chatMSG(id, outpu);
}, 1000)
}
else {
clearInterval(id);
alert('stop');
}
}
</script>