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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:40:15+00:00 2026-05-29T15:40:15+00:00

Below is simple HTML form , there are two sets of controls on the

  • 0

Below is simple HTML form , there are two sets of controls on the page first set, second set.. The script for first set works perfectly fine for animation. How do I make that script generic for different kind of sets. Imagine I have 30 of these sets like this I need to do the animation, how do I pass the selector name as parameter to JQuery?

        <!DOCTYPE html>
    <html>
    <head>
      <style>
      div { background:#def3ca; margin:3px; width:80px;
      display:none; float:left; text-align:center; }
      </style>
      <script src="http://code.jquery.com/jquery-latest.js"></script>
    </head>
    <body>

 <!-- first set -->       
      <button id="showr">Show</button>
      <button id="hidr">Hide</button>
      <div>who are you?</div>

 <!-- second set --> 
     <button id="showr1">Show</button>
      <button id="hidr1">Hide</button>
      <div id="div1">how are you?</div>


<!-- script works on First set -->
    <script>
    $("#showr").click(function () {
      $("div").first().show("fast", function showNext() {
        $(this).next("div").show("fast", showNext);
      });
    });

    $("#hidr").click(function () {
      $("div").hide(1000);
    });
    </script>



    </body>
    </html>
  • 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-29T15:40:16+00:00Added an answer on May 29, 2026 at 3:40 pm

    You should switch to classes. You can’t have multiple objects with the same id, but a class can be on multiple objects and then a single action in jQuery can operate on multiple objects. I’d suggest changing the HTML to this:

    <!-- first set -->       
     <div class="container">
         <button class="showr">Show</button>
         <button class="hidr">Hide</button>
         <div class="msg">how are you?</div>
     </div>
    
     <!-- second set --> 
     <div class="container">
         <button class="showr">Show</button>
         <button class="hidr">Hide</button>
         <div class="msg">how are you?</div>
     </div>
    
     <!-- third set --> 
     <div class="container">
         <button class="showr">Show</button>
         <button class="hidr">Hide</button>
         <div class="msg">how are you?</div>
     </div>
    

    And, then the script can be like this:

    <script>
    $(".showr").click(function () {
      $(this).closest(".container").find(".msg").show();
    });
    
    $(".hidr").click(function () {
      $(this).closest(".container").find(".msg").hide(1000);
    });
    </script>
    

    By using .closest() and making a container div and giving the target div for hide/show a class of it’s own, we make the jQuery code much more independent of the exact physical HTML so it doesn’t rely on there being nothing between elements.

    If you’re trying to make them all cascade so when you show the first one, it then (one at a time) shows all the other ones (regardless of how many there are), you could do that like this:

    <script>
    $(".showr").click(function () {
    
        function showItem(container)
            container.find(".msg").show(function() {
                showItem(container.next(".container"));
            });
        }
    
        showItem($(this).closest(".container"));
    });
    
    $(".hidr").click(function () {
        $(this).closest(".container").find(".msg").hide(1000);
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The simple code block below can be served up in a static HTML page
I'm borrowing/adapting this simple html/javascript form set up to put some data in the
I'm looking at creating a very simple HTML page that contains an HTML form
I have a simple form with some plain html input like bellow using ASP.NET
Below is the code of a simple html with a table layout. In FF
i want to synchronise a simple html list, like the one below with a
I am using the PHP below to submit data from an html form to
BACKGROUND: When you have a page that includes an HTML form, and you refresh/reload
I have a simple form like below that I have added the jQuery validations
See the simple form below. It's just a text box on top of a

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.