How can I hide (and fadeIn) a chosen select?

Christian Beil picture Christian Beil · Oct 22, 2012 · Viewed 14k times · Source

I'm using the Chosen library (http://harvesthq.github.com/chosen/) as JQuery plugin to enhance select elements. I need to initially hide (and then fadeIn) the select, but the way below doesn't seem to work.

<!doctype html> 
<html lang="en"> 
<head>
   <link rel="stylesheet" href="chosen/chosen.css" />
</head>
<body>
   <select id="firstChosenSelect" data-placeholder="Choose a Country..." style="width:350px;" tabindex="2">
      <option value=""></option> 
      <option value="United States">United States</option> 
      <option value="United Kingdom">United Kingdom</option> 
      <option value="Afghanistan">Afghanistan</option>
   </select>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
   <script src="chosen/chosen.jquery.js" type="text/javascript"></script>
   <script type="text/javascript">
     $('#firstChosenSelect').chosen();
     $('#firstChosenSelect').hide();
   </script>
</body></html>

Answer

Adil picture Adil · Oct 22, 2012

Put the select in span and hide/show the span

In html

<span id="spanForfirstChosenSelect" >
  <select id="firstChosenSelect" data-placeholder="Choose a Country..." style="width:350px;" tabindex="2">
      <option value=""></option> 
      <option value="United States">United States</option> 
      <option value="United Kingdom">United Kingdom</option> 
      <option value="Afghanistan">Afghanistan</option>
  </select>
</span>

In javascript

<scirpt type="text/javascript>    
     document.getElementById('spanForfirstChosenSelect').display = 'none';
</script>

In jQuery

<scirpt type="text/javascript>    
     $('spanForfirstChosenSelect').hide();
</script>