+ 4
hello everybody can someone help me please.
hello everybody can someone help me please. I would to create an html page that contain two divs with two table.they must toggle every 5 s and when the users click the toggle must stop, and when it's a double click the toggle must continue.
2 Answers
+ 1
i create the toggle and it work with this :
var intervalID = setInterval(function() {
$("#mydiv2").toggle();
$("#mydiv1").toggle();
}, 5000);
setTimeout(function() {
clearInterval(intervalID);
}, 20000);
but the click and double click didnt work
+ 5
You can use setInterval method with toggle() method on HTML elements. And clearInterval method with the click event.
A sample code.
//Assume you have 2 divs with id a and b.
//toggling the element every 5 seconds for div#a
var a1 = setInterval(()=>{
$("#a").toggle();
},5000);
//toggling the element every 5 seconds for div#b
var b1 = setInterval(()=>{
$("#b").toggle();
},5000) //5s is mentioned in 5000 ms
//clearing the interval upon clicking
$("#b").click(()=>{
clearInterval(b1);
});
$("#a").click(()=>{
clearInterval(a);
});
$("#a").dblclick(()=>{
//TODO: use the above snippet with some decision making statements.
});