-2

I have a URL stored in a variable and would like to increment the number at the end of the image name by 1 when a user clicks,

$(document).on('click', 'a.next', function(e){
        e.preventDefault();
        var URL = "http://www-url.com/img/436x768/look1.png";

});

How could I go about this? thanks.

user1937021
  • 10,151
  • 22
  • 81
  • 143

1 Answers1

4
var counter=0 // global variable

$(document).on('click', 'a.next', function(e){
    e.preventDefault();
    counter++; // add 1 to variable
    var URL = "http://www-url.com/img/436x768/look"+counter+".png";

});
Jamie Barker
  • 8,145
  • 3
  • 29
  • 64