Guest User

Untitled

a guest
May 26th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. var nav = document.getElementById('nav'),
  2. links = nav.getElementsByTagName('a'),
  3. select = document.createElement('select'),
  4. option = document.createElement('option');
  5.  
  6. for (var i = 0; i < links.length; i++){
  7. var link = links[i],
  8. _option = option.cloneNode(false);
  9. _option.value = link.href; // Set the option's value to the original link
  10. _option.innerHTML = link.innerHTML; // Set the option's text to the original text
  11. // if this link matches the current URL, add a selected attribute
  12. if( window.location.href == link.href ) {
  13. _option.selected = 'selected';
  14. }
  15. select.appendChild(_option);
  16. };
  17.  
  18. select.addEventListener('change', function() {
  19. window.location = select.value;
  20. }, false);
  21.  
  22. nav.parentNode.insertBefore(select, nav);
  23. nav.style.display = 'none';
Add Comment
Please, Sign In to add comment