Making Better Select Elements with jQuery and CSS3

Making Better Select Elements with jQuery and CSS3

When creating your web designs, you are always striving for a consistent look across the different browsers. Unfortunately, one of the most fundamental elements of your website – the browser controls – also prove the most difficult to style. Some of them, like the select element, are impossible to change beyond a certain extent.

This is why, today we are building a script that is going to take an ordinary select element, and replace it with a better looking, markup powered version, while keeping all the functionality intact.

Per popular demand, this script is now available as a stand-alone jQuery plugin. Read more and download the code at our Converting jQuery Code into a Plugin tutorial.

The HTML

As usual, we are start with the HTML part of the tutorial. I am using the HTML5 markup as it gives us some useful features, such as the data attributes, with which we can add arbitrary data to the markup of the page.

select-jquery.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Making Better Select Elements with jQuery and CSS3 | Tutorialzine Demo</title>

<link rel="stylesheet" type="text/css" href="css/styles.css" />

</head>
<body>

<div id="page">
	<h1>Your Product</h1>

	<form method="post" action="">

    	<!-- We are going to use jQuery to hide the select element and replace it -->

		<select name="fancySelect" class="makeMeFancy">

        	<!-- Notice the HTML5 data attributes -->

	        <option value="0" selected="selected" data-skip="1">Choose Your Product</option>
        	<option value="1" data-icon="img/products/iphone.png" data-html-text="iPhone 4&lt;i&gt;in stock&lt;/i&gt;">iPhone 4</option>
        	<option value="2" data-icon="img/products/ipod.png" data-html-text="iPod &lt;i&gt;in stock&lt;/i&gt;">iPod</option>
            <option value="3" data-icon="img/products/air.png" data-html-text="MacBook Air&lt;i&gt;out of stock&lt;/i&gt;">MacBook Air</option>
            <option value="4" data-icon="img/products/imac.png" data-html-text="iMac Station&lt;i&gt;in stock&lt;/i&gt;">iMac Station</option>
        </select>
    </form>

</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/script.js"></script>

</body>
</html>

You can see that we are using the data attributes to embed information in the option elements of the select. We are including a product icon and a rich text description, both of which are later displayed in the improved version of the select element.

I’ve set an arbitrary data-skip attribute on the first element, so that our script knows not to include it in the generated list. You could alternatively just check for the existence of the data-icon and data-html-text attributes and skip the element if necessary.

At the bottom of the document are included version 1.4.3 of jQuery (the latest version of the library as of this writing) and our script.js, which you can see in the next step.

A Better Select Element with jQuery & CSS3

A Better Select Element with jQuery & CSS3

The jQuery

On the document.ready event, jQuery inspects the select element, and using the data attributes, constructs the markup you can see below, which is appended just after the select:

<div style="width: 144px;" class="tzSelect">
	<div class="selectBox">iMac Station</div>
	<ul class="dropDown">
		<li><img src="img/products/iphone.png"><span>iPhone 4<i>in stock</i></span></li>
		<li><img src="img/products/ipod.png"><span>iPod <i>in stock</i></span></li>
		<li><img src="img/products/air.png"><span>MacBook Air<i>out of stock</i></span></li>
		<li><img src="img/products/imac.png"><span>iMac Station<i>in stock</i></span></li>
	</ul>
</div>

As you can see, we are basically constructing an unordered list, with a li element representing each option of the select. The select box itself is represented by a div with a .selectBox class.

Now lets take a closer look at how this code is generated.

js/script.js

$(document).ready(function(){

	// The select element to be replaced:
	var select = $('select.makeMeFancy');

	var selectBoxContainer = $('<div>',{
		width		: select.outerWidth(),
		className	: 'tzSelect',
		html		: '<div class="selectBox"></div>'
	});

	var dropDown = $('<ul>',{className:'dropDown'});
	var selectBox = selectBoxContainer.find('.selectBox');

	// Looping though the options of the original select element

	select.find('option').each(function(i){
		var option = $(this);

		if(i==select.attr('selectedIndex')){
			selectBox.html(option.text());
		}

		// As of jQuery 1.4.3 we can access HTML5
		// data attributes with the data() method.

		if(option.data('skip')){
			return true;
		}

		// Creating a dropdown item according to the
		// data-icon and data-html-text HTML5 attributes:

		var li = $('<li>',{
			html:	'<img src="'+option.data('icon')+'" /><span>'+
					option.data('html-text')+'</span>'
		});

		li.click(function(){

			selectBox.html(option.text());
			dropDown.trigger('hide');

			// When a click occurs, we are also reflecting
			// the change on the original select element:
			select.val(option.val());

			return false;
		});

		dropDown.append(li);
	});

	selectBoxContainer.append(dropDown.hide());
	select.hide().after(selectBoxContainer);

	// Binding custom show and hide events on the dropDown:

	dropDown.bind('show',function(){

		if(dropDown.is(':animated')){
			return false;
		}

		selectBox.addClass('expanded');
		dropDown.slideDown();

	}).bind('hide',function(){

		if(dropDown.is(':animated')){
			return false;
		}

		selectBox.removeClass('expanded');
		dropDown.slideUp();

	}).bind('toggle',function(){
		if(selectBox.hasClass('expanded')){
			dropDown.trigger('hide');
		}
		else dropDown.trigger('show');
	});

	selectBox.click(function(){
		dropDown.trigger('toggle');
		return false;
	});

	// If we click anywhere on the page, while the
	// dropdown is shown, it is going to be hidden:

	$(document).click(function(){
		dropDown.trigger('hide');
	});
});

On page load, the script scans through the options of the select element, and generates the markup according to the HTML5 data attributes that these items contain. As of jQuery 1.4.3, it is possible to access the values of these attributes directly with the jQuery data() method. This is a really handy feature, which makes it really easy to read the embedded data.

The original select element is not destroyed – it is only hidden with the hide() method. This is important, because as you can see from the code above, we are reflecting any changes of the selection back to that original select element. This way, when you use the select as part of a form, the values will be properly recorded and passed to your backend script.

Now that we have our code in place, lets take a closer look at the CSS3 magic that makes it all possible.

The CSS

As you can see from the markup at the top of the previous step, we are only using a minimal amount of markup to display the select box and the drop down. If we were confined to use pre-CSS3 techniques, we would have to add significantly more divs and spans.

css/styles.css

#page{
	width:230px;
	margin:100px auto;
}

#page h1{
	font-weight:normal;
	text-indent:-99999px;
	overflow:hidden;
	background:url('../img/your_product.png') no-repeat;
	width:230px;
	height:36px;
}

#page form{
	margin:20px auto;
	width:200px;
}

.tzSelect{

	/* This is the container of the new select element */

	height:34px;
	display:inline-block;
	min-width:200px;
	position:relative;

	/* Preloading the background image for the dropdown */
	background:url("../img/dropdown_slice.png") no-repeat -99999px;
}

.tzSelect .selectBox{
	position:absolute;

	height:100%;
	width:100%;

	/* Font settings */

	font:13px/34px "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	text-align:center;
	text-shadow:1px 1px 0 #EEEEEE;
	color:#666666;

	/* Using CSS3 multiple backgrounds and a fallback */

	background:url('../img/select_slice.png') repeat-x #ddd;
	background-image:url('../img/select_slice.png'),url('../img/select_slice.png'),url('../img/select_slice.png'),url('../img/select_slice.png');
	background-position:0 -136px, right -204px, 50% -68px, 0 0;
	background-repeat: no-repeat, no-repeat, no-repeat, repeat-x;

	cursor:pointer;

	-moz-border-radius:3px;
	-webkit-border-radius:3px;
	border-radius:3px;
}

.tzSelect .selectBox:hover,
.tzSelect .selectBox.expanded{
	background-position:0 -170px, right -238px, 50% -102px, 0 -34px;
	color:#2c5667;
	text-shadow:1px 1px 0 #9bc2d0;
}

CSS3 allows us to assign multiple background images to elements by just adding multiple url() declarations divided by a comma. They are added to the element from top to bottom, with each consecutive background displayed below the previous.

The Select Item Deconstructed

The Select Item Deconstructed

Currently multiple backgrounds are supported by Firefox, Safari, Chrome and Opera. For Internet Explorer and older versions of the first browsers, a fallback is defined, which is basically just a regular version of the background. When parsing the CSS document, browsers that do not understand multiple background will just ignore the rule and use the plain one.

.tzSelect .dropDown{
	position:absolute;
	top:40px;
	left:0;
	width:100%;
	border:1px solid #32333b;
	border-width:0 1px 1px;
	list-style:none;

	-moz-box-sizing:border-box;
	-webkit-box-sizing:border-box;
	box-sizing:border-box;

	-moz-box-shadow:0 0 4px #111;
	-webkit-box-shadow:0 0 4px #111;
	box-shadow:0 0 4px #111;
}

.tzSelect li{
	height:85px;
	cursor:pointer;
	position:relative;

	/* Again, using CSS3 multiple backgrounds */

	background:url('../img/dropdown_slice.png') repeat-x #222;
	background-image:url('../img/dropdown_slice.png'),url('../img/dropdown_slice.png'),url('../img/dropdown_slice.png');
	background-position: 50% -171px, 0 -85px, 0 0;
	background-repeat: no-repeat, no-repeat, repeat-x;
}

.tzSelect li:hover{
	background-position: 50% -256px, 0 -85px, 0 0;
}

.tzSelect li span{
	left:88px;
	position:absolute;
	top:27px;
}

.tzSelect li i{
	color:#999999;
	display:block;
	font-size:12px;
}

.tzSelect li img{
	left:9px;
	position:absolute;
	top:13px;
}

The box-sizing property that I’ve used for the .dropDown class, specifies how borders add up to the total size of the element. Normally, the borders here would increase the overall width with 2px and ruin the alignment. With box-sizing set to border-box, however, the overall width will not exceed the one specified in the definition and borders will take up space on the inside.

With this our jQuery and CSS3 powered select box  is complete!

Parting Words

In this tutorial we demonstrated some of the handy features that were introduced with jQuery 1.4.3 and a bit more of CSS3′s abilities. A good thing about this script, is that it keeps the original select box hidden on the page, and changes its value according to the fancy replacement. This way, when you submit the form the correct value is also passed along.

Join our newsletter and get our PSDs!17,396 people learn about HTML5, JS and more. Join them!

by Martin Angelov

Martin is a web developer with an eye for design from Bulgaria. He founded Tutorialzine in 2009 and publishes new tutorials weekly.

73 Comments

  1. Tristan says:

    This is very awesome! I wonder what you have in store for us next week...

    1. James Woods says:

      Great work - unfortunately there seems to be a problem using later versions of the jquery lib (jquery-1.7.0) - any thoughts?

  2. Zach says:

    Awesome will definitely use this with twtnotes! here's a demo of it http://screenr.com/J1k

  3. Great work! Just one tips: it's better if you preload 'li' background for better effect.

    1. Martin Angelov says:

      Thanks for the suggestion! I added a CSS declaration in .tzSelect so that the background image is now preloaded. I also updated the article and the download.

  4. I am not an expert but it is not working with different option values! select.val(i) at script.js on line 46 should be select.val(option.val()) or option.attr("selected","selected").

    1. Martin Angelov says:

      You are right! I updated the article and the download.

  5. Sebastian says:

    Nice as always! I don't think I can find 1 mediocre tutorial on this site - all are awesome!

  6. Martin Angelov says:

    Thank you for the awesome comments folks!

  7. steve mc says:

    I have to admit, the tuts on this site are always presented as beautiful as the content.

    Love your work, style, simplistic approach and range.

    Avid fan.

  8. Joey says:

    Good job!Thanks~

  9. Alex says:

    Another amazing tutorial, thanks a lot for this!

  10. Codeforest says:

    Martin, great article as always. Thanks

  11. Wow, very nice. It even (surprising to me) passed the "will it work in IE9" test! Kudos!

  12. Matt says:

    Looks good. Now do it with 0 images and I'll really be impressed!

  13. Matt Stow says:

    "While keeping all the functionality intact?" Umm, how about being able to use the keyboard? That's some pretty big functionality that has been lost here.

    1. Martin Angelov says:

      You are correct. I should change it to "most of the functionality intact". Other than that, keyboard navigation should probably be included in version 2.0

  14. Poster Nutbag says:

    This is great!

    The only issue I see is that you've used the html5 data feature to put style *back* into the HTML document. You are defining the icon for each option, an essential part of style, within the HTML doc. I haven't really thought about it any further yet, but naturally, there's a way you could instead use an ID for each option and assign a CSS-defined image for each option using it's ID. And you could use the 'rel' tag within the option to define the text. Or an image w/ its own 'alt' text within each option, which would give you both image *and* text. And so on.

    Doing so also wouldn't *require* the use of HTML5, allowing for wider adoption and greater platform conformity. Just sayin'.

    Again, apart from this one aspect, I think the overall technique and end result are great! Good work.

    Cheers.

    1. Martin Angelov says:

      Thank you for the comment.

      I always try to keep my markup to a minimum, and decided it was a good place to demonstrate jQuery's new data() method enhancements.

      You are, however, free to modify the script as you see fit.

      I also don't think that option elements are supposed to contain anything other than plain text. You can think of it this way: instead of adding an additional image element, just specify it into the data-icon attribute.

  15. Kevin Rapley says:

    This has blown my mind, this opens up some fantastic opportunities to enhance web forms appearance.

    I have tried adding multiple select boxes to a page, and any more than just the one fails to reveal the drop down on click. I was expecting that the class could be added to any select input that has the correct data attributes. Any idea why this is?

    I cannot wait to see how you handle radio buttons and check boxes!

    1. Kevin Rapley says:

      Digging a little deeper, it looks as though all of the options from each select is appended to every ul in the drop down and the show and hide functionality is prevented from working when there are multiples. It would be great if this was encapsulated so that it worked for multiple select groups.

      1. Martin Angelov says:

        Yes, encapsulation would be a good enhancement to the script. I will tackle it during the weekend and turn it into a jQuery plugin.

        1. Macklin Chaffee says:

          Is there a chance you've turned this into a plugin? Or, at the very least, have to create a script that allows for multiple selects on the same page?

          Thanks for your efforts on this, saved me a bunch of time.

        2. Kailash Gyawali says:

          Any updates on making it work multiple select in one page?

          1. Jenna says:

            Have you found a way to make this successful. I was wondering if we could create the drop down selection boxes to sit side by side instead of on top of other one. and that the drop down boxes would work.

  16. Salas says:

    Beautiful!!
    Thank you (=

  17. SamsonDelila says:

    Wow! Nice CSS element application !
    I'll use it on my project! Thanks and keep on your work !

  18. Mezanul says:

    Hello Martin,

    I recently found your site. The tutorials that you write are simply awesome and I really appreciate the fact that you explain everything in detail.

    I have been to other similar sites too and I can tell you, I have never seen any site that explains like you do.

    Kudos for your nice work. :)

  19. Shay says:

    Is it possible to add a link to them?.. i tried but didnt success.

  20. Just wondering, it's possible to drop down the menu on mouse hover instead of mouse click.........
    Srry about my english, I'm still learning. :)

    1. Martin Angelov says:

      Try this code (place it inside the $(document).ready function in script.js):

      selectBox.mouseenter(function(){
          dropDown.trigger('show');
      });
      
  21. Beben Koben says:

    its really a better...thanks^^

  22. Oliver says:

    I added it to some forms, but I had to edit a few things. First of all, I do not need the image order data features and the width of the div was wrong because of some paddings inside the form. Then I want to use the keyboard, so I changed the hiding of the the select field.

    select.css({"position":"absolute","left":"-9999px"}).after(selectBoxContainer);

    Next, I added this event:

    select.bind("change keypress keyup", function(){
    selectBox.html(select.find(':selected').text());
    });

    and I added a focus to the select field inside the toggle event:

    }).bind('toggle',function(){
    select.focus();
    if(selectBoxContainer.hasClass('expanded')){
    dropDown.trigger('hide');
    }
    else dropDown.trigger('show');
    });

    This is still not ideal, because the dropdown does not scroll to the actual entry, but you can now use the tabkeys to jump to the selectfield and change it with the keyboard.

    There is another technique to add better selectfields, but it uses the whole jquery ui lib and I do not want to load 40 kb of code, that is unused on the rest of the page.

    Another suggestions: Please remove the textshadow on focus of this textarea. If you select a part of the text, it is really unreadable.

    1. Oliver says:

      Oh, and I do not use the multiple background, but gradients and a em element, that is shown as a little arrow. Looks nice and does not need any images.

  23. Shay says:

    Anyway we can add a link to them?

  24. Amazin utilization of CSS3 and jQuery. This tutorial showed me that I have so much to learn...

  25. Chandan Chakraborty says:

    great :)

  26. Daniel S says:

    Awesome Work and great explained! Thanks for that!

  27. Igor Klajo says:

    Nice and functional script, thanks for the share.

    I ran into a small problem when more than one select box is present on one and the same page. The drop down function isn't working. I get the styling working, but when I click on the the select box, the drop down list won't show up. Is it possible to make multiple selects work with this script?

    Or is it working and I'm doing something wrong

  28. Giorgos says:

    Very nice and useful tutorial!!

    But i'd like to know if we want when we click an option instead of showing in select dropdown to take the value of the option and move on a link, how this could be added as function in script file?!!

    For example if you want when you choose iPod to link to iPod's website how could be done??
    Thanks

    1. Giorgos says:

      Martin, I tried to add in script file in:

      li.click(function(){

      and before:

      selectBox.html(option.text());
      dropDown.trigger('hide');

      // When a click occurs, we are also reflecting
      // the change on the original select element:
      select.val(option.val());

      return false;
      });

      dropDown.append(li);

      the follow:

      switch ($('#getdropdown :selected').val()) {
      case '1':
      document.location.href="www.something.com";
      case '2':
      document.location.href="#";
      case '3':
      document.location.href="#";
      }

      But I see that when you click the first option, do nothing and if you click it second time it moves to the location you define.

      How could be fix this and link to the location in first click??!!

  29. Kaven says:

    Hi Martin,
    Very nice works from you, but I am having a same problem with Giorgos, which i can't add in a link to the value. and really hope can get some advise from you. Thanks!

  30. Hi Martin.
    Event types of "change" don't work.
    The solution of the following:
    Need to add the following line of code

    select.trigger('change');

    After

    select.val(option.val());

    Or

    select.val(option.val()).trigger('change');

    Good luck!
    And thanks for this plugin :)

    1. Bugsy says:

      Thanks for the solution but I have one question. using the

      select.val(option.val()).trigger(‘change’);

      In my case I have two different dropdown menus areas in the same page. I named them with different classname on the script file.
      One is the regularSelect and I don't want the .trigger('change') it has the standard submit button. The other one 'mysort' I need the .trigger('change') so it goes to the href page (onChange). If I add:

      $('.mysort').val(option.val()).trigger('change');

      Applies the trigger to both. I tried to .unbind('change') but doesn't work. Is there a way to stop the .trigger change for the regularSelect?

      1. Bugsy says:

        I found the solution to having two dropdown menus in the same page with different functions. One has a link to the value.
        jquery.tzSelect.js before:

        select.val(option.val());
        

        Add:

        if dropDown.hasClass('dropDown mynewclass')){
        	select.val(option.val()).trigger('change');
        }
        else 
        

        On the script.js after:
        className : 'hasDetails'
        });

        Add your new class:

        //mynewclass menu class
        	$('select.sortBy').tzSelect({
        		render : function(option){
        			return $('',{
        				html:	'<a href="'+option.text()+'" / rel="nofollow">'+
        						option.text()+'</a>'
        			});
        		},
        		className : 'mynewclass'
        	});
        

        You can modify the html to fit your needs. Replace mynewclass with you class name.
        Hope this help.

    2. Guy Labbé says:

      Hi!
      This should be included in the script. Thanks for the tipp, I needed that, and wouldn't have found it else :)

  31. Tomas Misura says:

    Absolutely awesome

  32. Bugsy says:

    The html: didn't upload correctly, change it to fit your needs.

  33. ganesh says:

    hi it's great ................thankx.......!

    i wondering if it possible to give scroll bar
    thanks in advance

  34. ganesh says:

    hello guy i found answer of my own question

    .tzSelect .dropDown{
    	position:absolute;
    	top:40px;
    	left:0;
    	width:100%;
    	border:1px solid #32333b;
    	border-width:0 1px 1px;
    	list-style:none;
    	-moz-box-sizing:border-box;
    	-webkit-box-sizing:border-box;
    	box-sizing:border-box;
    	-moz-box-shadow:0 0 4px #111;
    	-webkit-box-shadow:0 0 4px #111;
    	box-shadow:0 0 4px #111;
    	overflow: scroll;
    	height: 250px;
    }
    

    it's give you scroll bar to drop box option

  35. Dego says:

    Hello,
    i made a Onchange function to my select, but dosen't work.
    Please help !

  36. Waut says:

    I was trying this with the latest jquery-library and it didn't work. But I found the solution.

    Apparently they don't use className anymore. But if you change that to class, everything is solved. I hope I saved someones time with this.

    Also, to get the selected index in the jquery cod/plugin, this could be handy

    if(i==select.find('option:selected').index()){
    	selectBox.html(option.text());
    }
    

    And thank you for all the tutorials. Keep it up :D

    1. Li77leMowgli says:

      Thanks a lot, you saved me a lotta time ;)

      It works with jQuery 1.7 too ;)

  37. RakeshSoni says:

    Thanks for the custom drop down solution and nice code.
    but I have one issue with custom drop down. I am developing the website for "iPhone, iPad and iPod". when using custom drop down it is working perfect. but when I have added google map with custom drop down on a page, the custom drop down start creating a problem. when user click on drop down, only drop down border display to the user (all the items just become invisible). without google map everything is working fine. can you please help me to solve the issue ?

    1. RakeshSoni says:

      Also the custom drop down with google map is working fine in system browser like Firefox, chrome.....etc. but it is creating issue in case of iPhone browser only

  38. Socrates says:

    Wish this would work with jquery 1.6+

    1. Charles Robbs says:

      Me too!!

    2. quero says:

      replace the className with 'class'.. would be first step (dont forget the quotes!)

      and as Waut mentioned earlier, you have to replace

      if(i==select.attr('selectedIndex')){
      selectBox.html(option.text());
      }

      with

      if(i==select.find('option:selected').index()){ selectBox.html(option.text()); }

      Worked out well for me..

  39. Hi Martin. Thanks for this tutorial!! Works great!! Question: Is it possible to load a cufon font in my dropdown? I don't get at what point I should do the cufon font replacement, if it's even possible.

    Thanks!

  40. John says:

    I was wondering is there is a way to allow the use of two or more select objects using this code on the same page. I have tried to add an additional select element within the html and when i do so it losses funcationality.

  41. João Cunha says:

    Nice job Martin, great explanation,

    tested in ie8, ie9, chrome, firefox and safari latest versions, works great on all.

    thanks for sharing

  42. Josh says:

    Great Post! A small query. When I updated the jquery to latest jquery-1.7.2. the select element vanishes. What's the issue?

    1. Linas says:

      Yes, facing the same issue. It's because of the variable names in the library, need to catch those and replace with old ones, but no luck yet.

  43. Aditi N says:

    Hey, Thanks for the wonderful tutorial. However m stuck in a problem. I've edited the css as per my requirement, but somehow there is blank space on left side (assigned for images I guess) which is just not ready to go. I don't want any images in the list just simple text. can somebody help me out with this & let me know what changes are supposed to be done in css or js to remove the blank space on left. I've removed the left:88px; from ".tzSelect li span", but the blank space is still there.

  44. Linas says:

    Great! Works like a charm!

  45. LP says:

    can anyone turn this code into a jquery plugin??,
    i tried to do it, but i couldn't...

    it would be absolutely great! =)

  46. Ross says:

    With the latest jquery (1.8.x) the combo is not visible. To make it visible change the javascript file with the following:

    var selectBoxContainer = $('<div>',{
    		width		: select.outerWidth(),
    		className: 'tzSelect',
    		html		: '<div class="selectBox"></div>'
    	});
    
    var dropDown = $('<ul>',{class:'dropDown'});
    

    with this:

    var selectBoxContainer = $('<div>',{
    		width		: select.outerWidth(),
    		'class'		: 'tzSelect',
    		html		: '<div class="selectBox"></div>'
    	});
    
    	var dropDown = $('<ul>',{'class':'dropDown'});
    

    and

    if(i==select.attr('selectedIndex')){
    	selectBox.html(option.text());
    }
    

    with this:

    if(i==select.find('option:selected').index()){
    	selectBox.html(option.text());
    }
    
    1. Eddi says:

      Martin thanks a lot for the Tutorial!
      Ross thanks a lot for the advise. Got crazy about why it does not work, but no everything is fine...
      thanks ;)

  47. efx says:

    For new versions of jQuery, selectedIndex is now a property, so you have to replace

    if(i==select.attr('selectedIndex')){
    	selectBox.html(option.text());
    }
    

    with

    if(i==select.prop('selectedIndex')){
    	selectBox.html(option.text());
    }
    
  48. oxana says:

    Martin thanks for the code but how to connect the links that I want the choice of one shift on a link to another page. 2 - another etc

  49. Rob says:

    I've having trouble with the drop down li not being on top of other elements on the page. I've tried adding z-index to no avail. This is true of other html/form elements as well as other selects created by this code. It's kinda hard to select an option when it is under other select boxes.

  50. bluet says:

    Great plugin. Just wondering how to make each of the list items a link to an external page?

Add Comment

Add a Reply

HTML is escaped automatically. Surround code blocks with <pre></pre> for readability.
Perks:   **bold**   __italics__   [some text](http://example.com) for links