Skip to content
Create a gist now

Instantly share code, notes, and snippets.

convert nav links to <select>
var nav = document.getElementById('nav'),
links = nav.getElementsByTagName('a'),
select = document.createElement('select'),
option = document.createElement('option');
for (var i = 0; i < links.length; i++){
var link = links[i],
_option = option.cloneNode(false);
_option.value = link.href; // Set the option's value to the original link
_option.innerHTML = link.innerHTML; // Set the option's text to the original text
// if this link matches the current URL, add a selected attribute
if( window.location.href == link.href ) {
_option.selected = 'selected';
select.addEventListener('change', function() {
window.location = select.value;
}, false);
nav.parentNode.insertBefore(select, nav); = 'none';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.