Tuesday, 27 August 2013

Populating jQuery Drop Down Menu items

Populating jQuery Drop Down Menu items

Hello I am trying to basically feed my navigation into a jQuery drop down
list, but can't get it to display anything... I have tried adding my link
list near the bottom replacing:nav a.. or should I be creating a style in
the css for nav a with my links at that location? Here is my full code:
$("nav select").change(function() {
window.location = $(this).find("option:selected").val();
});
// Create the dropdown base
$("<select />").appendTo("nav");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo("nav select");
// Populate dropdown with menu items
$("nav a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo("nav select");
});
I am using the Shopify platform and intending this for a mobile version of
a Navigation menu. If I could get any help, I would greatly appreciate it!

No comments:

Post a Comment