Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pibby/6641873 to your computer and use it in GitHub Desktop.
Save pibby/6641873 to your computer and use it in GitHub Desktop.
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