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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:22:01+00:00 2026-05-27T22:22:01+00:00

I am using a lightbox triggered by many elements. I need to alter the

  • 0

I am using a lightbox triggered by many elements. I need to alter the style (light to dark) when one unique element is clicked so I added an id to that element. I then force the css default on each click of lightbox but added an override on the #saved id. I am still learning jquery. Assuming I may need to unload that first click function.

What happens is that if #saved is clicked it is always ignored however it works fine the second time forward. Even clicking from .lightbox to #saved elements back and forth triggers properly. Addditionally if a .lightbox element is clicked first, then #saved – #saved lunches with the correct css. In conclusion the only time this fails on the first click is if #saved is the first element with a class of .lightbox that is clicked.

HTML:

Typical
<a href="/" class="lightbox">click me</a>

Unique
<a href="/" class="lightbox" id="saved">click me too</a>

JavaScript:

$(document).ready(function() {
var cssLB='.jquery-lightbox-mode-html .jquery-lightbox-background,.jquery-lightbox-loading,.jquery-lightbox-mode-html .jquery-lightbox-loading';

$('.lightbox').lightbox().click(function(){$(cssLB).css('background','#FFF url(/inc/img/loading.gif) no-repeat center center;')});

$('#saved').click(function(){
  $(cssLB).css('background','#000 url(/inc/img/loading-dark.gif)');
});
  • 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-27T22:22:02+00:00Added an answer on May 27, 2026 at 10:22 pm

    To avoid situations where you cannot determine the order the event handlers are called, you should do a single bind and identify the best route from there..

    Also you should use classes instead of manually changing the CSS.

    CSS

    .typical{background: #FFF url(/inc/img/loading.gif) no-repeat center center;}
    .unique{background: #000 url(/inc/img/loading-dark.gif);}
    

    jQuery

    $(document).ready(function() {
        var cssLB='.jquery-lightbox-mode-html .jquery-lightbox-background,.jquery-lightbox-loading,.jquery-lightbox-mode-html .jquery-lightbox-loading';
    
        $('.lightbox').lightbox().click(function(){
            if ( $(this).is('#saved') ){
                $(cssLB).removeClass('typical').addClass('unique');
            } else {
                $(cssLB).removeClass('unique').addClass('typical');
            }
    
        });
    });
    

    Additionally, if you have multiple elements that are saved then you should use a class instead of an id, as those should be unique..


    Update

    A note : the second class in your cssLB variable includes the third class. So you might want to remove the 3rd one.. (for performance).

    CSS precedence : If these classes have the background property defined, then you will have to increase the specificity of the typical and unique classes or apply the !important declaration to enforce them.

    Using !important

    .typical{background: #FFF url(/inc/img/loading.gif) no-repeat center center!important;}
    .unique{background: #000 url(/inc/img/loading-dark.gif)!important;}
    

    Using increased specificity

    .jquery-lightbox-mode-html .jquery-lightbox-background .typical,
    .jquery-lightbox-loading .typical,
    .jquery-lightbox-mode-html .jquery-lightbox-loading .typical {
        background: #FFF url(/inc/img/loading.gif) no-repeat center center;
    }
    .jquery-lightbox-mode-html .jquery-lightbox-background .unique,
    .jquery-lightbox-loading .unique,
    .jquery-lightbox-mode-html .jquery-lightbox-loading .unique{
        background: #000 url(/inc/img/loading-dark.gif);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that consists of one parent page. Using the lightbox-style jQuery
im using lightbox.js it needs prototype.js and i need to use jquery.js. Now both
I'm using Fancybox for a jQuery lightbox and it only works with one href
I am using a lightbox script, Clearbox . For various reasons ( main one
I am using jquery lightbox plugin colorbox ( http://colorpowered.com/colorbox/ ) and i want to
I am using a jquery lightbox plugin ( http://colorpowered.com/colorbox/ ) to load content using
A while back I created a lightbox plugin using jQuery that would load a
I'm using sIFR in a page that's being popped up in a nyroModal lightbox,
I've got a page where I'm using Mootools 1.2.4 and MediaboxAdvanced as a lightbox.
I'm using a (modal) lightbox on a page of my website to display my

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.