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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:56:37+00:00 2026-05-23T15:56:37+00:00

I have a div that can display 3 images (in the background) each indicating

  • 0

I have a div that can display 3 images (in the background) each indicating the ‘state’ of some variable: i.e., partial, full and none. For each of these states I have images: partial.gif, full.gif and none.gif (i.e., these are background images of that div)

Need: Circular queue like toggling effect for changing the images in this order partial -> full -> none -> partial

So if the current image is ‘partial.gif’ and the user clicks the div the background image changes to the next one in the sequence i.e., full.gif (and if it is currently full.gif it changes to none.gif and that to partial.gif and so on).

Naive solution: have a bunch of if/else’s or switch-case and check the current one (image) and then decide based on array look up which is the next one. Is this the best way of doing it? Can I leverage jQuery’s toggle function somehow?

(PS: It need not be restricted to images, but could also be for different background color sequences etc., I’d like to know what it is a good ‘generic’ way of doing it i.e., The example may be specific for background images but if I changed part of that code for background-color or font it should still work. I don’t want it to be purely generic, but just enough so it is easy to modify for other attributes. If not, that’s fine too. Just a thought 🙂

  • 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-23T15:56:39+00:00Added an answer on May 23, 2026 at 3:56 pm

    http://api.jquery.com/toggle-event/

    To be precise http://api.jquery.com/toggle-event/#example-0
    does exactly what you wanted…

    $("#div1").toggle(
      function() {
        $(this).css("background-image","url(full.png)")
      },   
      function() {
        $(this).css("background-image","url()")
      },   
      function() {
        $(this).css("background-image","url(partial.png)")
      }
    });
    

    UPDATE fn.toggle was removed from jQuery

    Here are relevant posts

    • Where has fn.toggle( handler(eventObject), handler(eventObject)…) gone?
    • Toggle stopped working after jquery update
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div box (black) that will display a few different product images
I have a div that can have various heights based on the size of
I have a div that contains 3 fields You can see the image here
So I have a Div containing an iframe that I can Clone using JQuery.
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
OK, so I have an internal div that is designed to contain text, images,
I have an annoying display issue in IE (7/8). I have some tabs that
I have an empty div called #lightPole that has a background image of a
I'm testing a new site, and I have a div with background-color: #bbf6bb; That
I have 2 buttons that should display above another div. But in Internet Explorer,

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.