Created
August 17, 2017 21:22
-
-
Save rhcarlosweb/9a96393bc38ef2bffb11f1ffbf2bfb75 to your computer and use it in GitHub Desktop.
Convert ul li on dropdown
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 listToDropdown(selector) { | |
var $list = $(selector), | |
$select = $('<select class="btn btn-outline btn-white select-field-menup" />'); | |
// blank | |
$select.append($('<option />').attr('value', '').html('Navegação')); | |
// for each list change to a option in select field | |
$list.children('li').each(function(index, el) { | |
// extract url from link | |
urlLink = $(this).children('a').attr('href'); | |
// extra text link | |
textLink = $(this).children('a').text(); | |
$select.append($('<option />').attr('value', urlLink).html(textLink)); | |
}); | |
$list.replaceWith($select); | |
} | |
$('.select-field-menup').change(function(event) { | |
var url = $(this).val(); // get selected value | |
if (url) { // require a URL | |
window.location = url; // redirect | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment