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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:59:19+00:00 2026-06-02T22:59:19+00:00

Conditional statements dont appear to be working for me. Im trying to a set

  • 0

Conditional statements dont appear to be working for me. Im trying to a set of stacked images to change their zIndex based on the zIndex of the one being selected. So if i have a few buttons to call up a few images to the front:

(assume we started out on the first image by default and are selecting the 2nd image)

<script>
$(function() {
    var z = $("#image2").zIndex;  //also tried .css.zIndex;
    $("#button2").click(function() {
        if (z != 999 ) {
            $("#image1").animate({zIndex: 0}, 1, 'linear');
            $("#image2").animate({zIndex: 999}, 1, 'linear'); 
        } else {
        return false;
        };  
    });
});
</script>

The problem is that while it does work, it works regardless of whether the condition is true or not, so if i select the 2nd image then select it again it will run the script. Now before you start wondering why that matters, there’s more going on than just that, which is causing visual errors to occur otherwise id just leave it at that, but this is the gist of it.

  • 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-02T22:59:20+00:00Added an answer on June 2, 2026 at 10:59 pm

    You can do either:

    $("#image2")[0].style.zIndex // document.getElementById(image2).style.zIndex
    

    or

    $("#image2").css('zIndex');
    

    What you have here is a native JavaScript property getter/setter hanging off a jQuery collection, and that’s simply not how that works.

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

Sidebar

Related Questions

I'm trying to use the IE specific conditional statements to alter class settings based
I'm currently using HTML conditional statements to select a CSS file based on IE
I see in PHPBB they use conditional statements inside their HTML, or XHTML; if
I'm having a problem getting one of my conditional statements to display data correctly.
How do conditional statements (like IF ... ELSE ) affect the query execution plan
Is there any way to use conditional statements in CSS?
What is the best way to evaluate simple conditional statements like: a>b ? x-4<10+y
HI, I need to write multiple statements inside a conditional operator. What will be
Is there anything wrong with using ternary operators in place of longer conditional statements
I'm trying conditional formatting on a sheet. I need to fill the cells with

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.