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();

)};

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();          

    });
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.