Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created August 7, 2012 17:06
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save billerickson/3287337 to your computer and use it in GitHub Desktop.
WordPress Menu as Select Dropdown (js)
jQuery(document).ready(function($){
// Create the dropdown base
$('<div class="mobile-menu"><form><select onchange="if (this.value) window.location.href=this.value" /></form></div>').prependTo("#wrap");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo(".mobile-menu select");
// Populate dropdown with menu items
$("#nav a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo(".mobile-menu select");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment