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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:04:48+00:00 2026-06-09T12:04:48+00:00

This is the sequel to this thread: 4 toggle buttons speak javascript to each

  • 0

This is the sequel to this thread:
4 toggle buttons speak javascript to each other but none of them are good listeners

Our heros have overcome the ridiculous amount of nonsense originally presented in the fiddle http://jsfiddle.net/EjW7A/8/ (no longer available) when @nbrooks -reinvigorated by the forces of good- conquered all of the stupidly placed arrays, functions and the mammoth amount of redundant content with his solution:

http://jsfiddle.net/EjW7A/24/

We rejoin Luhring after 8 hours of poking, prodding, red bull drinking, concrete wall head-bashing at the final step of solving the epic problem of doom- implementation:

The new fiddle:

http://jsfiddle.net/Luhring/EjW7A/38/

Problem:

How can I insert the content dynamically- allowing each button to toggle it’s own content while making sure the other buttons are toggled off and their content hidden? ex, if button 1 is toggled on (it is animated as if it were a ‘real’ pressed button), button 1s content is displayed in a gallery where the contents can be clicked to display a lightbox. when button 2 is clicked should toggle button 1 off and replace button 1’s contents with its own.

  • 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-09T12:04:49+00:00Added an answer on June 9, 2026 at 12:04 pm

    New Working Demo

    Anything invoking jQuery on DOM elements must be wrapped within the DOM ready function to work correctly (this is why your $('a').click() was failing. Also, normally if you see yourself creating multiple arrays that you never end up using, and still end up referencing each element directly, you’re making a lot of wasted effort. I cleaned your code up a bit – take a look:

    jQuery(document).ready(function($) {
        //variable declaration section.
        var contentArray = ['albumArt', 'logoDesign', 'UX', 'other'],
            content = {}, newClassName, $selectedArray, i;
    
        for ( i = 0; i < contentArray.length; i++) {
            var className = contentArray[i];
            content[className] = $('.' + className);
        }
    
        //prevent links that are clicked from going anywhere
        $("a").click(function(e) {
            e.preventDefault();
        });
    
        $('.workTypes').click(function() {
            if ($(this).is('#centeringDiv a')) return;
    
            $(this).toggleClass('workTypesSelected');
            $('.workTypesSelected').not(this).removeClass('workTypesSelected');
    
            $selectedArray = content[$('.workTypesSelected').attr('id')];
            $('#galleryDiv').empty();
    
            if ( $selectedArray ) {
                // note creates #largeGallery elements dynamically
                for ( i = 0; i < $selectedArray.length; i++ ) {
                    var $selected = $selectedArray.eq(i);
    
                    $('<a>').attr({
                        href: $selected.attr('href'),
                        title: $selected.attr('title'),
                        class: "lb_gal"
                    }).append(
                        $('<img>').attr({
                            id: "largeGallery"+i,
                            src: $selected.attr('href'),
                            class: "gallery cf"
                        }).rlightbox()
                    )
                    .appendTo('#galleryDiv')
                    .rlightbox();
                }
            }
    
        }); // end click handler
    }); //end the document ready jquery function​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a sequel to my (other) dumb question that I have asked today
This question is a sequel to this question (I have applied the answer, but
This is somewhat of a sequel to Slow Exists Check . Alex's suggestion works
This question is sort of a sequel to that question. When we want to
[for those not following along at home, this is the sequel to Rolling My
In a sequel question to this question , my corporate environment lacks the libpython2.6.so
I get this error when running Heroku db:push --app myapp. Sequel::AdaptorNotFound -> LoadError: no
I'd like to not store times in my local timezone, but Sequel is making
This question is sequel of this one. So any idea how to decode this
I thought I could figure this out on my own, but apparently I am

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.