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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:50:20+00:00 2026-05-28T05:50:20+00:00

I asked a similar question here where I wanted to get a single div

  • 0

I asked a similar question here where I wanted to get a single div to show/hide rather than all the divs. This was solved and I used one of the answers provided. However further down the line I ran into some problems where it would open the wrong corresponding div and it was suggested that I use ID’s to open the correct corresponding div. The divs are dynamically generated along with their ID’s and they are matching as expected.

My problem is that the jQuery script doesn’t work any more (i’ve rewritten it using advice from other answers in the previous question) – does anyone know what the problem is?

Here is the code (jsFiddle)

  • 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-28T05:50:21+00:00Added an answer on May 28, 2026 at 5:50 am

    A quick look at the javascript console (F12) showed the following error message:

     Uncaught ReferenceError: $index is not defined
    

    This error is raised because you are trying to use the variable $index outside of the scope it is defined (within the click handler).

    Here is a working modified version with the following alterations:

    • within an event handler, using this.id is sufficient to get the ID of an element as this in an event handler is a DOMElement and not a jquery object

    • use .replace() or .substring() to get the last two digits of the id. .charAt() only returns 1 character at the specified position

    • the ID selector in jquery is #<id> –> "#slidingDiv" + idx

    • only prefix the jquery variables with $, not regular variables. it is just a convention but when you see $myvariable you then expect it to be a jquery object


    DEMO

    $(document).ready(function() {
    
        $(".slidingDiv").hide();
        $(".show_hide").show();
    
        $(".show_hide").click(function() {
            var id = this.id;
            var idx = id.replace('show_hide', '');
            //var idx = id.substring(id.length-2);
            var divName = "#slidingDiv" + idx;
            $(divName).slideToggle();
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar to the question I asked here , if I wanted to list all
I found this on Google, click here , which someone asked a similar question,
Liu Chang asked a very similar question to this one here, Linux equivalent of
This question is very similar to the question asked here so I hope this
I asked a similar question here a while back but all the answers were
I realize that there was a similar question asked here , but this is
I already asked similar question here, but I still get some errors, so I
I saw a similar question asked and answered for ASP.net here How do I
I asked a similar question about this previously, but I did not specify that
I've asked similar question here because I thought the problem was in my custom

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.