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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:59:50+00:00 2026-06-15T04:59:50+00:00

I am trying to hide and show tags in a dropdown list, which I

  • 0

I am trying to hide and show tags in a dropdown list, which I initially managed to get work in everything bar Internet Explorer. I then found that wrapping the options that needed to be hidden in tags solved the IE problem. But i’m now having an issue with removing them, because the code that I have written also removes the dropdown that they are contained in. What am I doing wrong? Here is the code so far:

function GetMonthsForSelectedYear() {
    var selectedYear = $("#DropDownListYear option:selected").text(),
        currentYear = (new Date()).getFullYear(),
        currentMonth = (new Date()).getMonth() + 1;

    $("#DropDownListMonth option").each(function() {
        if (selectedYear == currentYear) {
            var option = $(this).index();
            if (option < currentMonth) {
                $(this).wrap('<span>').hide();
            }
        } else {
            $(this).unwrap("<span>").show();
        }
    });
}

$("#DropDownListYear").change(function() {
   GetMonthsForSelectedYear();
});​

And here is is in JSFiddle:

http://jsfiddle.net/MGGh9/1/

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-06-15T04:59:52+00:00Added an answer on June 15, 2026 at 4:59 am

    Instead you can just use this:

    $("#DropDownListMonth option[value=" + title + "]").hide();
    

    When you wrap a <span>, it wraps the whole <select>, not just that <option>. And this is an expected behaviour. Moreover, it is not a right way to have anything other than option or optgroup inside a select tag.

    In your code:

    function GetMonthsForSelectedYear() {
        var yearOfEntry = $("#DropDownListYear option:selected").text(),
            currentYear = (new Date()).getFullYear(),
            currentMonth = (new Date()).getMonth() + 1;
    
        $("#DropDownListMonth option").each(function() {
            if (yearOfEntry == currentYear) {
                var option = $(this).index();
                if (option < currentMonth) {
                    $(this).hide();               // «--------- This one
                }
            } else {
                $(this).show();                   // «--------- This one
            }
        });
    }
    
    $("#DropDownListYear").change(function() {
       GetMonthsForSelectedYear();
    });​
    

    Fiddle: http://jsfiddle.net/MGGh9/2/

    Also Check:

    1. How to hide a <option> in a <select> menu with CSS?
    2. How can I hide select options with JavaScript? (Cross browser)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work out an hide/show function according to, if the div's are
I'm trying to use JQuery to show/hide div tags based on the selected index
I am trying to show hide div blocks depending on the link on which
I'm trying to toggle (hide/show) a table when clicking a button which is located
I am trying to hide and show a list from a certain point. But
I am trying to hide and show different div's depending on which radio you
i'm trying to hide/show some control on a page from Page_LoadComplete. If a put
I am trying to hide/show a class of elements in a form depending on
I am trying to hide/show/toggle a div when a button is clicked. I am
I'm developing smartphone hybrid applications. I'm trying to hide/show a <div> with slideDown /

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.