Created
June 15, 2011 10:43
-
-
Save KrofDrakula/1026866 to your computer and use it in GitHub Desktop.
Select box replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$(function() { | |
var selectBoxes = $('select'); | |
selectBoxes.each(function() { | |
var $select = $(this).hide(), | |
$proxy = $('<ul class="selectbox"/>').insertAfter($select); | |
$select.find('option').each(function() { | |
// we iterate through the options and create a list item with data-value as value | |
$proxy.append('<li data-value="' + this.value + '">' + $(this).text() + '</li>'); | |
}); | |
$proxy.delegate('option', 'click', function(ev) { | |
// update the original select box when an option is selected | |
$select.val($(this).attr('data-value')); | |
}); | |
// attach more delegates and/or hide members based on other fields | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment