Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created October 18, 2012 04:42
Show Gist options
  • Save jaredatch/3909892 to your computer and use it in GitHub Desktop.
Save jaredatch/3909892 to your computer and use it in GitHub Desktop.
create select from navigation
// Create the dropdown base
$("<select />").appendTo("nav");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo("nav select");
// Populate dropdown with menu items
$("nav a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("nav select");
});
$("nav select").change(function() {
window.location = $(this).find("option:selected").val();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment