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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:30:24+00:00 2026-05-17T20:30:24+00:00

My apologies if this is just another question that gets asked over and over.

  • 0

My apologies if this is just another question that gets asked over and over. I’ve found some similar questions, the examples just haven’t gotten me exactly where I need to be. This is similar to jQuery Closures, Loops and Events.

$('a.highslide').each(function() {
  hsGroup = $(this).attr("rel");

  if(hsGroup.length > 1){
     hsGroup = hsGroup.replace(/\s/g , "-");     
  }    

  this.onclick = function() {
    return hs.expand(this, { slideshowGroup: hsGroup });

  }
});

this code setsup an onclick that launches a highslide popup. I’ve added the slideshowGroup property and the hsGroup code above it which pulls the contents of the Rel attribute to define the group of each. The issue as you may see right away is the contents of hsGroup is not local to that anon function. So at run time its value is always the same for each link the is applied to. I’ve looked through some closure examples but have thus far failed to make them work in my situation.

Thanks,

  • 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-17T20:30:24+00:00Added an answer on May 17, 2026 at 8:30 pm

    You just need a var to make it per link, like this:

    $('a.highslide').each(function() {
      var hsGroup = $(this).attr("rel");
      //^ -- add this
    
      if(hsGroup.length > 1){
         hsGroup = hsGroup.replace(/\s/g , "-");     
      }    
    
      this.onclick = function() {
        return hs.expand(this, { slideshowGroup: hsGroup });
    
      }
    });
    

    Without the var you have one global hsGroup variable that’s getting reused for every loop, and ending up with the same, last value used in every click.

    Or, just do the replacement at the time of the click event, like this:

    $('a.highslide').click(function() {
      var hsGroup = $(this).attr("rel");
      if (hsGroup.length > 1) hsGroup = hsGroup.replace(/\s/g , "-");    
      return hs.expand(this, { slideshowGroup: hsGroup });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just checking out F#, so apologies if this is a silly question,
First off, apologies if this question has been asked before but I couldn't find
Apologies if this ends up being a stupid question, but I was just wondering
I am just getting started with IoC containers so apologies if this is a
Greetings, Apologies in advance that I have not researched this toughly enough to answer
Final question for the night. And apologies for the complete noobness of this. I
If this question has already been asked I appologies, please point me in the
I'm new to C#, so apologies if this is an obvious question. In the
I'm a student of web development (and college), so my apologies if this comes
I apologise in advance if this question isn't very specific. Would it be possible

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.