Skip to content

Instantly share code, notes, and snippets.

@mdcpepper
Created July 6, 2009 13:47
Show Gist options
  • Save mdcpepper/141433 to your computer and use it in GitHub Desktop.
Save mdcpepper/141433 to your computer and use it in GitHub Desktop.
jQuery function for converting an unordered list of links to a select element 'jumpbox'
jQuery.fn.ul_to_select = function(){
return this.each(function(){
var select_box = document.createElement('select');
select_box.id = this.id + '_select'
this.parentNode.insertBefore(select_box, this);
$('<option></option>').html('Choose...').appendTo('#'+select_box.id);
$(this).find('li a').each(function(link){
$('<option></option>').html(this.innerHTML).attr('value', this.href).appendTo('#'+select_box.id);
});
this.parentNode.removeChild(this);
$('#'+select_box.id).change(function(){
document.location.href=$('#' + select_box.id + " option:selected").val();
return false;
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment