Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery change href when image slider changes
    text
    copied!<p>I have a working image slider that uses jQuery to change the image (yes, I know using background images in DIVs is not the best practice, but it's the only method that works with the rest of my page):</p> <p>My HTML:</p> <pre><code>&lt;a id="featuredLink" href="#"&gt;&lt;div class="featuredImages" style="background-image:url('http://www.placehold.it/2000x500/00ff00.png')"&gt;&lt;div class="slide"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/a&gt; </code></pre> <p>jQuery:</p> <pre><code>var urls = [ 'http://www.google.com','http://www.microsoft.com','http://www.yahoo.com' ]; var images = [ 'http://www.placehold.it/2000x500/ff0000.png','http://www.placehold.it/2000x500/00ff00.png','http://www.placehold.it/2000x500/0000ff.png' ]; var cur_image = 0; function changeBackground() { cur_image++; if ( cur_image &gt;= images.length ) cur_image = 0; // change images $( '.featuredImages' ).css({ backgroundImage: 'url(' + images[ cur_image ] + ')' }); $( '.featuredImages .slide' ).fadeOut( 3000, function(){ $( this ).css({ backgroundImage: 'url(' + images[ cur_image ] + ')' }).show(); } ); } setInterval( changeBackground, 10000 ); </code></pre> <p>And CSS:</p> <pre><code>.featuredImages { position:absolute; margin: 0; height: 500px; width: 100%; background: transparent url('') no-repeat center; overflow: hidden; } .featuredImages .slide { position: absolute; margin: 0; height: 500px; width: 100%; background: transparent url('') no-repeat center; overflow: hidden; } </code></pre> <p><a href="http://jsfiddle.net/hnS9U/1/" rel="nofollow">http://jsfiddle.net/hnS9U/1/</a></p> <p>I would like to change the href of that anchor tag ("featuredLinks") when the image swaps so that it links to the page that the images relates to.</p> <p>I would like to use an array to store the links ("urls") and the same loop counter that is used for the images to keep track of what link to use.</p> <p>Any pointers in the right direction would be great!</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload