Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS: Convert navigation to select dropdown on mobile
// Convert page navigation to dropdown menu on smaller screens
$(function() {
$("<select />").appendTo("#navigation .wrapper");
$("<option />",
{
"selected": "selected",
"value" : "",
"text" : "Page Menu" // default <option> to display in dropdown
}).appendTo("#navigation .wrapper select");
$("#navigation .wrapper a").each(function()
{
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("#navigation .wrapper select");
});
$("#navigation .wrapper 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