Select2 placeholder does not work (solution)

I was frustrated by select2 plugin. I did not understand why on plugin’s homepage placeholder works and on my site doesn’t. I tried to google it and i found that you must add <option></option> for your select. I tried to add multiple options with value but placeholder did not work. The first option must be empty in order to get placeholder working!
Like this:

<select id="sel" placeholder="Hello">
  <option></option>
  <option>Option value</option>
</select>

<script type="text/javascript">
  $("#sel").select2();
</script>

Here is working example: http://hromnik.com/web/select2/
Check source code for details.

Advertisements