0

All the characters in breaking down a string confuse me.

I'm trying to understand how to find whatever number is in a string, and increment it up/down by one (unless it's a known last or first number?)

$('#arrow_prev').click(function(){

var whichgallery = $('#div_id').attr('class');
// this could be .class_1 through .class_12

var nextgallery = ".".(return whichgallery.replace(/\d+$/, function(s) {
    return +s+1;);



        //something like this?

    $(nextgallery).click();

)};

Edited by turpentyne

1
Contributor
1
Reply
13
Views
4 Years
Discussion Span
Last Post by turpentyne
0

Actually, I made progress, but I still can't get a loop on the first and last one.

I'm now here:

$('#arrow_next').click(function(){

            var whichgallery = $('#div_id').attr('class');
            var newId  = whichgallery.replace(/(\d+)/, function(){return arguments[1]*1+1} );
            var newId2 = '.'+newId
            $(newId2).click();

    });

    $('#arrow_prev').click(function(){

            var whichgallery = $('#div_id').attr('class');
            var newId  = whichgallery.replace(/(\d+)/, function(){return arguments[1]*1-1} );
            var newId2 = '.'+newId
            $(newId2).click();          

    });
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.