Created
February 3, 2014 12:34
-
-
Save essejose/8783105 to your computer and use it in GitHub Desktop.
Create the dropdown in jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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