-
-
Save impronunciable/1754093 to your computer and use it in GitHub Desktop.
Change select to dropdown list
This file contains hidden or 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
var select_to_dropdown = function(el, dropdown, select_text ){ | |
$(el).children().hide(); | |
var sel_list = $('<div id="'+dropdown+'"><strong class="cta"><span></span></strong><ul></ul></div>'); | |
sel_list.find('span').text($(el + ' label').text()); | |
$(el + ' select').children('option').each(function(){ | |
sel_list.children('ul').append('<li>' + $(this).text() + '</li>'); | |
}); | |
$(el).append(sel_list); | |
$(dropdown).find('li').live('click',function(e){ | |
$(el + ' select option').eq($(this).index()).attr('selected','selected').siblings('option').removeAttr('selected'); | |
$(this).addClass('selected'); | |
$(this).siblings().removeClass(); | |
$(dropdown + ' strong span').text($(this).text()); | |
$(this).parent().slideUp('slow'); | |
$('input[name="'+select_text+'"]').val($(this).text()); | |
}); | |
$(dropdown + ' strong').live('click',function(e){ | |
e.preventDefault(); | |
$(dropdown + ' ul').slideToggle('slow'); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment