ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Change DIV background image randomly at regular interval in JavaScript<p>Hi <a class="username" rel="chetan"> chetan</a>,</p> <p>Check the below code.</p> <div class="demo_block"> <pre class="brush: html">&lt;div id=&#34;main_header_image&#34;&gt; header &lt;/div&gt; &lt;div id=&#34;main_header_image1&#34;&gt; header 1 &lt;/div&gt; &lt;div id=&#34;main_header_image2&#34;&gt; header 2 &lt;/div&gt; &lt;script type=&#34;text/javascript&#34;&gt; window.onload = function () { document.getElementById(&#39;main_header_image&#39;).style.backgroundImage = &#34;url(&#39;https://static.flickr.com/72/199481203_ad4cdcf109_s.jpg&#39;)&#34;; var rndImages = [ &#34;https://static.flickr.com/66/199481236_dc98b5abb3_s.jpg&#34;, &#34;https://static.flickr.com/75/199481072_b4a0d09597_s.jpg&#34;, &#34;https://static.flickr.com/57/199481087_33ae73a8de_s.jpg&#34;, &#34;https://static.flickr.com/77/199481108_4359e6b971_s.jpg&#34;, &#34;https://static.flickr.com/58/199481143_3c148d9dd3_s.jpg&#34;, &#34;https://static.flickr.com/72/199481203_ad4cdcf109_s.jpg&#34;, &#34;https://static.flickr.com/58/199481218_264ce20da0_s.jpg&#34;, &#34;https://static.flickr.com/69/199481255_fdfe885f87_s.jpg&#34;, &#34;https://static.flickr.com/60/199480111_87d4cb3e38_s.jpg&#34;, &#34;https://static.flickr.com/70/229228324_08223b70fa_s.jpg&#34;]; setInterval(function () { var i = Math.floor((Math.random() * rndImages.length)); document.getElementById(&#39;main_header_image&#39;).style.backgroundImage = &#34;url(&#39;&#34; + rndImages[i] + &#34;&#39;)&#34;; }, 2000); // Change 2000 to 10000. } &lt;/script&gt;</pre> </div> <p><a class="demo button orange btn btn-red">Demo</a></p>https://www.aspforums.net:443/Threads/677147/Change-DIV-background-image-randomly-at-regular-interval-in-JavaScript/https://www.aspforums.net:443/Threads/677147/Change-DIV-background-image-randomly-at-regular-interval-in-JavaScript/Mon, 08 Oct 2018 06:01:47 GMT