jQuery: hide and show for div's -
i want show div 3 sec. , show next div 3 sec. , continue timer. code not working if there other code solve problem.
var timer = setinterval(showdiv(3000)); var counter = 0; function showdiv() { if (counter ==0) counter++; $('#text1, #text2').stop().hide().filter(function() { return this.id.match('#text' + counter); }).show(); counter == 2? counter = 0 : counter++; } showdiv(); });
the filter function should return boolean value if element matches or not. here this.id.match returns array result of regular expression execution. instead of using function filter, can simplify this:
setinterval(showdiv,3000); var counter = 0; function showdiv() { if (counter ==0) { counter++;} $('#text1, #text2') .stop() .hide() .filter('#text'+counter) .show(); counter == 2? counter = 0 : counter++; }
Comments
Post a Comment