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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:13:00+00:00 2026-05-23T10:13:00+00:00

I am working on getting assigning a dynamic variable within Jquery in which the

  • 0

I am working on getting assigning a dynamic variable within Jquery in which the buttons could change to be more or less so I figured a loop would be best. (that rimes oo god it’s gotten to be that fun). So here is the break down in which I can not seem to get to figured out.

$(".acc_trigger").each(function(j) {

    $("#accord" + j).click(function() {
        $(".selectedimg").hide('drop', { direction: 'down' }, 1000);
        $(".selectedimg").removeClass("selectedimg");

        $("#accordimg"+ j ).addClass("selectedimg");
        $("#accordimg"+ j ).show('drop', { direction: 'up' }, 1000);

  });
});

For each class which are buttons add a click in which the id has a number to the end of it which removes the class selected but then replaces with the same number used in the id above. I can’t get this to work and have thought about using loops but when I do it goes the same number of times the loop is for. I’m trying to just create a number of click functions that allows for the variable to be dynamic to make it so I can have more or less buttons.

  • 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-23T10:13:01+00:00Added an answer on May 23, 2026 at 10:13 am

    You should be able to use jQuery’s live function to do this without having to use loops or anything.

    $('.CssClassThatAllYourButtonsShare').live('click', function() {
            $(".selectedimg").hide('drop', { direction: 'down' }, 1000);
            $(".selectedimg").removeClass("selectedimg");
    
            //Extract the number from the current ID
            var j = $(this).attr('id').match(/\d+$/);
    
            $("#accordimg"+ j).addClass("selectedimg");
            $("#accordimg"+ j).show('drop', { direction: 'up' }, 1000);
    });
    

    Documentation on Live: http://api.jquery.com/live/

    Description: Attach a handler to the
    event for all elements which match the
    current selector, now and in the
    future.

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

Sidebar

Related Questions

In my just-completed project, I was working getting distributed transactions working. We implemented this
I'm working on getting an Introduction to Groovy presentation ready for my local Java
I've been working on getting a 2.5 module ported to 3.0, mostly for my
I am working on getting familiar with the Android SDK and I have having
Ok I'm working on getting better with python, so I'm not sure this is
I am working on getting parameter from a function string. For example, my function
On the web side we are working on getting source control. Now, I want
I'm just getting started working with foreign keys for the first time and I'm
What's the secret to getting ClaimsResponse working with DotNetOpenId ? For example, in this
I'm looking for help getting started working programmatically with audio. Specifically, the platform I'm

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.