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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:20:01+00:00 2026-05-25T06:20:01+00:00

Im creating several grids with data using this code: @foreach(var set in viewModelEnvironment.SystemEnvironmentVariabelSets) {

  • 0

Im creating several grids with data using this code:

@foreach(var set in viewModelEnvironment.SystemEnvironmentVariabelSets) 
{
    <p class="slide"><a href="#" class="btn-slide">@set.Name</a></p>

         <div id="panelToHide">

        //Creating the grids for each set here...

        </div>
}

This creates a bunch of hidden “panels” with attached buttons. When clicking on one of these buttons I want the corresponding panel to expand. This is working if just one panel exxits by using this code:

     $(".btn-slide").click(function () {
        $("#panelToHide").slideToggle("slow");
        $(this).toggleClass("active"); return false;
    });

How can I use .click function on each unique panel and button that is created in the for-loop? How can i give each element in the for-loop a unique identifier and change the jquery function .click to correspond to each element individually?

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-25T06:20:02+00:00Added an answer on May 25, 2026 at 6:20 am
    $("a.btn-slide").each(function(idx,el){
        $(this).click(function(){
            $('div.panel:eq('+idx+')').slideToggle('slow');
            /*...*/
        });
    });
    

    this will work as long as the buttons and the panels are in the same serial order and the number of panels is the same as the number of buttons, like this:

    <a class="btn-slide">open first panel</a>
    <a class="btn-slide">open second panel</a>
    <a class="btn-slide">open third panel</a>
    
    <div class="panel">this is the first panel</div>
    <div class="panel">this is the second panel</div>
    <div class="panel">this is the third panel</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating several image dynamically using the following code: function refresh_gallery(galleryidentifier, albumid) {
In jQuery, I'm creating several div elements within a class: function class([..]) { this.par1
using c# (asp.net) i'm programmatically creating several drop down lists (random number). the user
I've seen several questions/answers related to entirely creating a button in code, but not
I have seen several methods for creating simple fixed width single column layout using
I'm creating new application using zend framework with several modules. Can you please advice
I have tried creating several web parts using Visual Studio 2010 using available guides
In my program, I am creating several threads in the main() method. The last
I'm creating a gem which has several scripts in the bin directory the utility
I'm creating a WPF application where several ListView selections are made in a row

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.