I have a function that uses setInterval, but I can´t stop the stop setInterval after it runs once, and don´t know why.
Here my code:
<script type="text/javascript" src="../front-end/js/jquery.min.js"></script>
<script type="text/javascript">
var jQuery1 = $.noConflict(true);
</script>
<script type="text/javascript" src="../front-end/js/jquery.gvChart-0.1.min.js"></script>
<script type="text/javascript">
var time = 0;
gvChartInit();
function coisa(){
time = setInterval(function() {
jQuery1(document).ready(function(){
jQuery('#chartdiv').gvChart({
chartType: 'PieChart',
gvSettings: {
vAxis: { title: 'No of Visitors' },
hAxis: { title: 'Month' },
width: 720,
height: 300
}
});
});
}, 1000);
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#jogador").hide()
$("#selecoes").hide();
$("#jogoss").hide();
$("#selecaoList").click(function () {
$("#index").hide();
$("#selecoes").show();
coiso();
coisa();
clearInterval(time);
});
$("#tagList").click(function () {
$("#index").hide();
$("#selecoes").show();
coiso();
coisa();
clearInterval(time);
});
When I run this every second print's a new chart, but I want that prints only a chart once.