[Solved] Change the src of an image with an Href [closed]


Sorry if it took long!

Here’s a working JsFiddle!

$(document).ready(function () {

     var items = $("nav.bgNav ul");
     var img = $("#bgStretchimg");

     next();

     function next() {

         var urlI = items.children('.active').children("a").attr('href');

         var nextI = items.children('li.active').removeClass("active").next();
         if (nextI.length == 0) {
             nextI = items.children().eq(0);
         }

         nextI.addClass('active');
         img.attr('src', urlI);

         // schedule next iteration
         setTimeout(function () {
             next();
         }, 2000);
     }
 });

If you want a delay before the first call you might want to put it in a setTimeout the same way it is in the function, so it waits before the first change.

// in document ready directly
setTimeout(function () {
    next();
}, 2000);    

Might also want to look for a plugin that is already built-up like this one : jQuery Cycle

3

solved Change the src of an image with an Href [closed]