javascript - Initiate click event automatically on a specified time interval -


how can make automatic click event on time interval set

 <div class="nav">             <img class="logo" src="images/logo.png" alt="logo" />             <ul class="navright">                 <li><a class="navlink select ho" href="#">home</a>•</li>                 <li><a class="navlink ab" href="#">about us</a>•</li>                            <li><a class="navlink pg" href="#">products</a>•</li>                            <li><a class="navlink ps" href="#">services</a>•</li>                            <li><a class="navlink cs" href="#">contact us</a></li>                       </ul>            </div>   

and jquery this

$(document).ready(function () {     var myinterval = true;      myinterval = setinterval(function () {         var iscroll = $(window).scrolltop();         if (iscroll + $(window).height() == $(document).height()) {             clearinterval(myinterval);         } else {             iscroll = iscroll + 200;             $('html, body').animate({                 scrolltop: iscroll             }, 1000);         }     }, 2000); }); 

you can trigger programmatically click on each element progressively using eq , execute click using trigger.

code:

$(document).ready(function () {     var totdivs = $(".navright li").length;     var currdiv = 0;     var myinterval = setinterval(function () {         if (currdiv > totdivs) {             clearinterval(myinterval);             return         }         $(".navright li").eq(currdiv).find('a').trigger("click");         currdiv++;      }, 2000); });  $(document).on("click", "a", function () {     alert($(this).text()); }); 

demo: http://jsfiddle.net/irvindominin/dysq6/


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -