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 9142833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:52:31+00:00 2026-06-17T09:52:31+00:00

In my page I have different menu items that trigger different corresponding pictures. The

  • 0

In my page I have different menu items that trigger different corresponding pictures. The z-index switches the corresponding picture to the top. Here is the code:

$(document).ready(function(){

var doorOpen = false;

$("a[href=#andrew]").click(function() {

    if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not
        var duration = 1500;
    } else {
        var duration = 0;
    }

    $("#rightdoor,#leftdoor").animate(
        {"marginLeft":"0px"},
        {duration:duration,
            complete:function() {
                $('.pic2 .pic3 .pic4 .pic5').css('zIndex', 1);  //puts wrong pics in back
                $('.pic1').css('zIndex', 2);  //brings right pic into view
                $('#rightdoor').animate({  //opens doors again
                 marginLeft: "150px",
                }, 1500);
                $('#leftdoor').animate({
                 marginLeft: "-150px",
                }, 1500);
            }
        }
    );

    doorOpen = true;


});

$("a[href=#bugz]").click(function() {

    if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not
        var duration = 1500;
    } else {
        var duration = 0;
    }

    $("#rightdoor,#leftdoor").animate(
        {"marginLeft":"0px"},
        {duration:duration,
            complete:function() {
                $('.pic1 .pic3 .pic4 .pic5').css('zIndex', 1);  //puts wrong pics in back
                $('.pic2').css('zIndex', 2);  //brings right pic into view
                $('#rightdoor').animate({  //opens doors again
                 marginLeft: "150px",
                }, 1500);
                $('#leftdoor').animate({
                 marginLeft: "-150px",
                }, 1500);
            }
        }
    );

    doorOpen = true;    
});
});

The problem is that the z-index works but only once per menu item it seems. If you initially click #andrew, it brings pic1 to the top and if you click #bugz it brings pic2 to the top. However, if you click #andrew again it animates the code before and after the .css(z-index) change but does not change the z-index to bring pic1 back to the top.

I am new to Javascript/JQuery so please forgive me if I am missing something obvious

  • 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-06-17T09:52:32+00:00Added an answer on June 17, 2026 at 9:52 am

    Your selector is wrong: $('.pic2 .pic3 .pic4 .pic5') looks for descendants of .pic2.

    You could use commas to separate those classes instead of spaces, but it’s simpler to use the .siblings method instead:

    $('.pic1').css('zindex',2).siblings().css('zindex',1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML: <ul class=vertical_menu no_select> <li class=edge_top>&nbsp;</li> <!-- Menu Items Here
I have this code that generates a WP menu: <div id=menu> <?php $args =
I have the following dilemma with two elements (menu items) that I need to
I have page where I use model which can have different types (depending by
On a page I have different element which I bound yo different Ajax calls.
Hi I have a page for which I have four different style sheets like
I have page where I load different videos.I use jw player as player if
I have two different buttons on my page. I want them both to be
I have 2 different group page with 2 look alike classes which using the
I am using django-registration and would like to have a different page for failed

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.