Created
July 6, 2009 13:47
-
-
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'
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
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