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

The Archive Base Latest Questions

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

I need to show/hide some divs depending on selected options. I’m using .change function.

  • 0

I need to show/hide some divs depending on selected options. I’m using .change function.

HTML looks more-less like this:

<div id="1" style="display:none">
</div>
<div id="WRAP">
  <div id="2" style="display:none">
  </div>
  <div id="3" style="display:none">
  </div>
</div>
<div id="4" style="display:none">
</div>

jQuery:

$(function(){
$('#fyo').change(function(){ 
        $('#' + $(this).val()).show('slow').children().show('slow');
        $('#' + $(this).val()).siblings().hide('slow');
        $('#' + $(this).val()).parent().show('slow').siblings().hide('slow');

    }); 
});

I won’t write the code for options but just FYI the options are as follows:

Choose option: 1  or  2  or  3  or 4  or WRAP (so 2 & 3).    

It should be possible to:

  1. show each of these divs separately, including inner divs – with all other divs hidden;
  2. <div id="WRAP"> should show all inner divs simultaneously.

The result I achieved is (almost) exactly what I needed but as I’m a beginner with jQuery, I was wondering if this is correct? Or is there any easier way to achieve this? There is one thing that makes me doubt that something is actually wrong – when I choose 2 or 3, it doesn’t display in the style of 'slow', but instead it’s almost immediate and looks like something is wrong because it doesn’t come out so smoothly.

  • 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-28T00:43:51+00:00Added an answer on May 28, 2026 at 12:43 am
     $('#' + $(this).val()).parent().show('slow').siblings().hide('slow');
    

    this will potentially mess with element you didnt mean to change. For instance if

    <body>
        <div class="AnimatedDivs">
            <div id="1" style="display:none">
            </div>
            <div id="WRAP">
              <div id="2" style="display:none">
              </div>
              <div id="3" style="display:none">
              </div>
            </div>
            <div id="4" style="display:none">
            </div>
        </div>
        <div class="Content">
        </div>
    </body>
    

    and you select 1 then

    $('#' + $(this).val()).parent() //Basically selects div with class "AnimatedDivs"
                          .show('slow') //Does show animation on it
                          .siblings() // select all siblings (this would include div with class "Content")
                          .hide('slow'); //Now hide it ( so now div.Content is hidden )
    

    its best to give them all a similar class like “hideableDiv” and do manipulations using that as a selector;

    <div id="1" class="hideableDiv" style="display:none">
    </div>
    <div id="WRAP" class="hideableDiv">
      <div id="2" class="hideableDiv" style="display:none">
      </div>
      <div id="3" class="hideableDiv" style="display:none">
      </div>
    </div>
    <div id="4" class="hideableDiv" style="display:none">
    </div>
    
    $('#fyo').change(function(){ 
    
        var divToShow = $('#'+$(this).val());
    
        //Hide them all except the one being shown, .not function removes the passed object from its selection
        $(".hideableDiv").not(divToShow).hide('slow');
    
        //Now show the one that was selected
        divToShow.show('slow');
        //Select parent (if it has class hideableDiv ) and show it
        divToShow.parent(".hideableDiv").show('slow');
    
        //If WRAP selected also show the children as well
        if( $(this).val() == "WRAP" )
            divToShow.children().show('slow');
    
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a show and hide function for some divs and more divs need
I'm using a bit of jQuery to expand/hide some divs. I need to add
Hi again :) I'm using jQuery script to show/hide some content: <script type=text/javascript> $('.toggleButton').click(function()
I'm new to jQuery and need some help to show and hide a div
I need to provide users with the ability to hide/show table columns. Using previous
Ok, I have a few divs within a section of HTML. I need some
I need to show the number of results for a given category, and hide
I need to show a modal popup if the user has selected a treeview's
I have some radio buttons and I'd like to have different hidden divs show
I need help, any ideas? Firstly i want to hide some input element when

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.