Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:43:35+00:00 2026-05-23T03:43:35+00:00

So, I have images in a div that share the same class and one

  • 0

So, I have images in a div that share the same class and one of them is selected at a time for a single view of that image. In this single view, I have arrows that I want to use to cycle between the images. The images sharing the same class have sequential alt values.

Right now, I can get the preceding alt value and set the src of the image in the single view to the source of that image. But, I can’t seem to get the same effect with the following image.

    $("#leftButton").click(function(){
            var current= $('img[id="selected"]');
            var altVal=current.attr("alt").valueOf()-1;
            if(altVal>=0)
            {
                var next= $('img[alt='+altVal+']');
                current.attr("id", "");
                next.attr("id", "selected");
                $("#embiggenImage").attr("src", next.attr("src"));
            }
        }
    );

    $("#rightButton").click(function(){
            var gal=$('img[class="galleryImage"]');
            alert(gal.length);
            var current= $('img[id="selected"]');
            var altVal=current.attr("alt").valueOf()+1;
            if(altVal<gal.length)
            {
                alert("inside");
                var next= $('img[alt='+altVal+']');
                current.attr("id", "");
                next.attr("id", "selected");
                $("#embiggenImage").attr("src", next.attr("src"));
            }
        }
    );

As you can see, the code for changing the sources is exactly the same, and it reaches those two alerts fine, but returns a null source.

Edit: It seems that in the leftButton click function, alt is being properly decremented, but in the rightButton click function, when I am trying to increment alt, it instead, is appending the ‘1’, such that the final value of altVal is ’01’. This does not make any sense to me..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:43:36+00:00Added an answer on May 23, 2026 at 3:43 am

    The problem is in the difference between these two lines:

    var altVal=current.attr("alt").valueOf()-1;
    var altVal=current.attr("alt").valueOf()+1;
    

    - only has one meaning: subtract. If you call it on a string, it will be converted into a number before the operation.

    + has two meanings: add and concatenate. If you call it on a number, it adds. If you call it on a string, it concatenates. attr returns a string (as does valueOf — I’m not sure what the point of that is), so +1 means “put add 1 to the end of the string”.

    You need to convert the value to a number instead. I’d use the unary + operator:

    var altVal = +current.attr('alt') + 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image <div class='container'> <img src='../images.jpg' alt='images' /> </div> I want to
I have a div contain the image inside it like this : <div class=gallery
I have the following HTML: <div class=connections> <h2>Grads that share your interests</h2> <div id=connections_nav
I have images that have statistics texts printed over them. This worked well with
Hi have a div that's wrapping images..The width of this DIV can change so
I have a bunch of images that are in a hidden div. The div
I have a div with id=images. The div contains some images that are each
I have a div that contains 3 fields You can see the image here
i have a div and and a looping move function that translates an image
I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.