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

  • Home
  • SEARCH
  • 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 3277736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:24:08+00:00 2026-05-17T19:24:08+00:00

I’ve recently discovered a website which does something really cool! Example: There are two

  • 0

I’ve recently discovered a website which does something really cool! Example:

  • There are two links “Cat” and “Dog”.
  • There are two DIV containers, id=”catImage” and id=”dogImage”
  • The initial URL looks like http://mysite.com/#cat
  • Initially, the cat image is visible
  • Clicking on the Dog link will fade out the catImage div and fade in the dogImage div
  • Additionally, it will change the anchor in the browser URL to: http://mysite.com/#dog
  • Opening the website with httü://mysite.com/#dog will show the dog image initially

Is this possible using jQuery? How would I scan for that anchor, and how would I call a function when the link is clicked without causing the link to follow some URL? I’m an objective-c dude and don’t know anything about JS… hope my question isn’t too dumb for you.

  • 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-17T19:24:09+00:00Added an answer on May 17, 2026 at 7:24 pm

    with this markup:

    <div id="images">
        <div id="catImage">some cat image here</div>
        <div id="dogImage" style="display:none;">some dog image here</div>
    </div>
    <div id="anchors">
        <a href="#cat">catImage anchor</a>
        <a href="#dog">dogImage anchor</a>
    </div>
    

    and with this js (assuming jquery 1.4.x)

        $(function () {
    
            $("#anchors a").click(function () {
                // send the index of the anchor to the function
                fadeImage($(this).index());
            });
    
            var hash = window.location.hash;
            if (hash) {
    
                var elementId = "#" + hash.substring(1) + 'Image';
                var $div = $(elementId);
    
                // check if this element exists, and if so, send that index to the function
                if ($div.length) {
                    fadeImage($div.index());
                }
    
            }
    
        });
    
        function fadeImage(index) {
            $("#images div:eq(" + index + ")").fadeIn().siblings().fadeOut();
        }
    

    And to explain what’s going on here:

    I’m using the jquery index() function to get the index of the element relative to its siblings. I then pass that index to the fadeImage function, which finds the same index div and fades it in. By using chaining, I then look to the siblings of that div to fade them out. This is useful if you have more than 2 divs to fade out here.

    For the anchor/hash usage, I just find the div with the matching id and get its index, and pass it to the same function.

    jQuery docs can explain the various methods much better than I can.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.