Solved

style="display:none" does not work for option element

Posted on 2007-12-04
4
5,775 Views
Last Modified: 2009-04-11
Hello
I have a select list and I need a way to set certain option tags invisible. I tried applying style="display:none" to the option tags but this has had no effect.
The reason for this is that I am going to use some JavaScript to dynamically enable some selections in the drop down list.
Please see the attached code snippet.
Thanks

<select id="counties" tabindex="1">
 <option value="">Select</option>
 <option style="display:none" value="IE76176089">Carlow</option>
 <option style="display:none" value="IE96268862">Cavan</option>
 <option style="display:none" value="IE55624026">Clare</option>
 <option style="display:none" value="GB55624026">London</option>
 <option style="display:none" value="GB55624026">Surrey</option>
</select>

Open in new window

0
Comment
Question by:mike99c
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Assisted Solution

by:SteveH_UK
SteveH_UK earned 166 total points
ID: 20402555
0
 
LVL 19

Accepted Solution

by:
erikTsomik earned 167 total points
ID: 20402757
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 167 total points
ID: 20413381
You can't hide options, you have to remove them from the select list if you don't want them to show up.

Here is how you dynamically add an option to the select list:

var o = document.createElement('option');
o.value = 'IE76176089';
o.text = 'Carlow';
document.getElementById('counties').options.Add(o);
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20548658
Checking back to see if you had any progress?
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bootstrap list items overlap 3 38
email validation 9 50
Popup write two lines 3 22
Can't get video to center on page 2 15
When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question