(can't use display:none) Remove extra space when using visibility:hidden

I hope someone can help me with this. I can't use display:none because it doesn't work in IE11

This is an example http://jsfiddle.net/we89rx4c/2/

You see I have
<option value="0" style="visibility:hidden"> first </option> 

Open in new window


You see how it leaves a space. Anyway I can remove the space?
I wanted to grey out the options when a user uses IE but y manager doesn't like that. He wants the option hidden like Chrome.
i1.png
LVL 8
CamilliaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Update your jquery to
<select id="to_folder" name="to_folder"> 
  <option value="">- move to folder -</option> 
  <option value="0" data-display="none"> first </option> 
  <option value="1">second</option> 
  <option value="2">third</option> 
</select>
<div class="folder" id="folder0">first one</div>
<div class="folder" id="folder1">second one</div>
<div class="folder" id="folder2">third one</div>

Open in new window

$(function() {
  $("#to_folder").on("change",function() {
    $(".folder").hide();
    var folderId = this.value;
    if (folderId !="") {
      $("#folder"+folderId).show();
    }
  });
  $("#to_folder").trigger("change"); // show/hide whatever matches the select
  
  $("#to_folder > option").each(function() {
     if($(this).data('display')=='none'){
     	$(this).hide();
     }
  });
 
  
});

Open in new window


http://jsfiddle.net/we89rx4c/13/
0
Branislav BorojevicWeb EnthusiastCommented:
Check the link below:

Added some javascript

http://jsfiddle.net/we89rx4c/11/

$('select#to_folder option[id=first]').attr('disabled', 'disabled').hide();

Open in new window


This hides the option in all browsers and disables if can't hide.

To bring back the option do not forget to enable it:

$('select#to_folder option[id=first]').removeAttr('disabled').show();

Open in new window

0
Michael VasilevskySolutions ArchitectCommented:
You can use the hidden attribute

<select id="to_folder" name="to_folder"> 
  <option value="">- move to folder -</option> 
  <option value="0" hidden> first </option> 
  <option value="1">second</option> 
  <option value="2">third</option> 
</select>
<div class="folder" id="folder0">first one</div>
<div class="folder" id="folder1">second one</div>
<div class="folder" id="folder2">third one</div>

Open in new window

1
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

CamilliaAuthor Commented:
Let me try. "Hidden" works in IE?
I'll post back.
0
Michael VasilevskySolutions ArchitectCommented:
Hidden should be supported.  See here. I understand it's part of HTML5.
0
CamilliaAuthor Commented:
1. Hidden didn't work in IE
2. .attr('disabled', 'disabled').hide(); greys out the options in IE but my manager doesn't want that.

My actual sample is here, you can download and click on page.html to see it

https://drive.google.com/open?id=1R2w3Ywvt0KQOHLwyqO34NWGLFVX6hjpo

I'll try Scott's solution.
0
CamilliaAuthor Commented:
Can't get it working in my sample code that I have on google drive. Don't know where to put Scott's code.

I changed the orig code from
      $('option', operatorSelect).not($("option[datatype *= '" + fieldDataType + "']", operatorSelect)).prop('disabled', true);

To this
$('option', operatorSelect).not($("option[datatype *= '" + fieldDataType + "']", operatorSelect)).attr('data-display', 'none');

I see it in Chrome (want to at least get it working in Chrome first) but then where do I put
$("#fieldOperator > option").each(function () {
		if ($(this).data('display') == 'none') {
			$(this).hide();
		}
	});

Open in new window



I'll keep working on it. If I figure it out, I'll post back
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Did you see in my post above I also linked to an updated fiddle? http://jsfiddle.net/we89rx4c/13/
0
Branislav BorojevicWeb EnthusiastCommented:
Camilia,

You can add
.remove()

Open in new window

to remove the selector option:

http://jsfiddle.net/we89rx4c/21/

Works on IE as well.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
Let me see again. I'll post back.
0
CamilliaAuthor Commented:
Works! thank you both. (I can't wait for this one project to end :))
1
Branislav BorojevicWeb EnthusiastCommented:
Happy to be of assistance, Camillia! Good luck in all future endeavors :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.