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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:12:28+00:00 2026-06-13T13:12:28+00:00

I am using the Colorbox Lightbox script to call a hidden div on a

  • 0

I am using the Colorbox Lightbox script to call a hidden div on a page. It works great but there is a catch. I have 15 hidden divs. When a link is clicked I would like a new lightbox to show each time without repeating until all have been shown. I do not know how to do this.

Here is my code to call the lightbox:

$(".colorbox").colorbox({
    inline:true 
});

Here is the HTML of the hidden divs

<div class="hide">
 <div id="lightbox1">
    <!-- Content --> 
 </div>
 <div id="lightbox2">
    <!-- Content --> 
 </div>
 <!-- etc -->
</div>

How would I call each div at random until all have been shown then start over?

Also is there a way that once divs 1 – 15 have been shown to then show one last div (id="last-div") before restarting?

Note: All divs would be called on a click and I am using jQuery 1.8.2.

I do not know where to start, I have seen scripts using Math.random() but I do not understand enough to make that work.

UPDATE

I have tried Ian’s answer but the lightbox is not showing (but I can see in the console log that the script is working)

Originally he has this in his script:

$(selector).show();

which I changed to this:

$(selector).colorbox({inline:true });

What do I need to do to call the lightbox?

Note: No errors are thrown.

  • 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-13T13:12:29+00:00Added an answer on June 13, 2026 at 1:12 pm

    So my idea was similar to Eric’s, but I wanted to make it work “completely”. So instead of storing references to all the divs in an array, I just decided to store an array of ints representing each div. The way I eventually select them with jQuery is "#lightbox + i", so if you don’t have this exact structure (where the divs have an id like “lightbox” and an int – from 1 to the last count), then you can use .eq() or nth-child. It won’t be the exact same results, but it will have the same random effect, just done in a different way. I found a function that “randomizes” an array – I’m guessing like what Eric’s Shuffle does. But here’s where I got it from – How to randomize (shuffle) a JavaScript array? . I had to modify it to return a new array instead of modify the one passed to the function. Also, I kept everything in the document.ready scope, instead of the global scope, so things are passed/returned a lot. It worked fine before when I had all and randomed declared globally and didn’t pass them around, I just thought this would be “better” since they weren’t global.

    Here’s the fiddle:

    http://jsfiddle.net/6qYCL/1/

    And here’s the Javascript:

    $(document).ready(function () {
        var all,
            randomed;
    
        all = generateAll();
        randomed = generateRandomed(all);
    
        $("#generator").on("click", function (evt) {
            evt.preventDefault();
            randomed = doNext(all, randomed);
        });
    });
    
    function generateAll() {
        // Generates the array of "all" divs to work on
        var a = [];
        var divs = $(".hide > div.lightbox");
        for (var i = 1; i <= divs.length; i++) {
            a.push(i);
        }
        console.log("List of divs available to toggle: " + a);
        return a;
    }
    
    function generateRandomed(all) {
        // Randomizes the original array
        randomed = fisherYates(all);
        console.log("Setting randomized array: " + randomed);
        return randomed;
    }
    
    function doNext(all, randomed) {
        $(".lightbox, #last-div").hide();
    
        if (randomed.length < 1) {
            console.log("All lightboxes toggled, showing last, then starting over");
            $("#last-div").show();
            randomed = generateRandomed(all);
        } else {
            var next = randomed.shift();
            var selector = "#lightbox" + next;
            console.log("Showing " + selector);
            $(selector).show();
            console.log("What's left: " + randomed);
        }
    
        return randomed;
    }
    
    // Randomizes an array and returns the new one (doesn't modify original)
    function fisherYates ( myArray ) {
      var return_arr = myArray.slice(0);
      var i = return_arr.length;
      if ( i == 0 ) return false;
      while ( --i ) {
         var j = Math.floor( Math.random() * ( i + 1 ) );
         var tempi = return_arr[i];
         var tempj = return_arr[j];
         return_arr[i] = tempj;
         return_arr[j] = tempi;
      }
      return return_arr;
    }
    

    It accounts for getting to the end of the list and display #new-div like you mentioned, then starting the process over. If you look in your browser’s console, you can “watch” what’s happening during initialization and when clicking the link.

    I think this is close to what you were looking for. I’m not sure which is a better solution – storing references to the elements or just an array of ints to loop through and eventually find. I know there are many variations on how to do this – when/how to store the counting stuff, when/how to randomize the array or retrieve a random value (and how to keep track of which has been used), where to store all references, and plenty more. I hope this at least helps!

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

Sidebar

Related Questions

I'm using Colorbox to show the html content of hidden divs on my page.
I am using colorbox.js to display some forms in a lightbox. There are multiple
I'm using colorbox on a div. I have nested div's. When i click the
I'm using the colorbox plugin for modal popups. It's working nicely, but there's a
i am using jQuery colorbox plugin. it is true with asp.net page but not
I have a page opening in an iframe using colorbox. This page has a
So I am using colorbox to create a lightbox. Currently I have it so
I am trying to display a hidden div in colorbox using an <a> link's
I have a website that consists of one parent page. Using the lightbox-style jQuery
I'm using Colorbox, and I want to load a specific div from another page

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.