Skip to content

Instantly share code, notes, and snippets.

@essejose
Created February 3, 2014 12:34
Show Gist options
  • Save essejose/8783105 to your computer and use it in GitHub Desktop.
Save essejose/8783105 to your computer and use it in GitHub Desktop.
Create the dropdown in jQuery
$(function() {
// Create the dropdown base
$("<select class='drop' />").appendTo("#menu2");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Veja Mais"
}).appendTo("#menu2 select");
// Populate dropdown with menu items
$("#menu2 a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("#menu2 select");
});
// To make dropdown actually work
// To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
$("#menu2 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