Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.appendChild(_option);
- };
- select.addEventListener('change', function() {
- window.location = select.value;
- }, false);
- nav.parentNode.insertBefore(select, nav);
- nav.style.display = 'none';
Add Comment
Please, Sign In to add comment