Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:38:08+00:00 2026-06-13T02:38:08+00:00

Is it possible for this jQuery code to run as a standalone javascript? This

  • 0

Is it possible for this jQuery code to run as a standalone javascript? This is the only javascript I’d like to use in my project so I’d prefer not to load the entire jquery library just for this 1k script.

//chris coyier's little dropdown select-->

$(document).ready(function() {

//build dropdown
$("<select />").appendTo("nav.primary");

// Create default option "Go to..."
$("<option />", {
   "selected": "selected",
   "value"   : "",
   "text"    : "Go to..."
}).appendTo("nav select");  

// Populate dropdowns with the first menu items
$("div#brdmenu ul li a").each(function() {
    var el = $(this);
    $("<option />", {
        "value"   : el.attr("href"),
        "text"    : el.text()
    }).appendTo("nav.primary select");
});

//make responsive dropdown menu actually work           
$("nav.primary select").change(function() {
    window.location = $(this).find("option:selected").val();
});

});

I’ve tried to find previous answers but most questions are for converting to jquery and not vice-versa 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:38:09+00:00Added an answer on June 13, 2026 at 2:38 am

    Here is something similar to market’s answer. I’m assuming you want to get all the links in UL elements inside the brdmenu element. If you only want the first link on the LI elements, just adjust the loop that gets them.

    Also, this is not a good idea. Using select elements for links went out of fashion a long time ago, users much prefer real links. Also, when navigating the options using cursor keys in IE, a change event is dispatched every time a different option is selected so users will only get to select the next option before being whisked away to that location. Much better to add a “Go” button that they press after selecting a location.

    The main change is to use an ID to get the nav.primary element, which I assume is a single element that you should be getting by ID already.

    function doStuff() {
    
        function getText(el) {
          return el.textContent || el.innerText;
        }
        var div, link, links, uls;
    
        // Use an ID to get the nav.primary element
        var navPrimary = document.getElementById('navPrimary');
    
        // Create select element and add listener
        var sel = document.createElement('select');
        sel.onchange = function() {
          if (this.selectedIndex > 0) {  // -1 for none selected, 0 is default
            window.location = this.value;
          }
        };
    
        // Create default option and append to select
        sel.options[0] = new Option('Go to...','');
        sel.options[0].setAttribute('selected','');
    
        // Create options for the links inside #brdmenu
        div = document.getElementById('brdmenu');
        uls = div.getElementsByTagName('ul');
    
        for (var i=0, iLen=uls.length; i<iLen; i++) {
          links = uls[i].getElementsByTagName('a');
    
          for (var j=0, jLen=links.length; j<jLen; j++) {
            link = links[j];
            sel.appendChild(new Option(getText(link), link.href));
          }
        }
    
        // Add select to page if found navPrimary element
        if (navPrimary) {
          navPrimary.appendChild(sel);
        }
    }
    
    window.onload = doStuff;
    

    It’s only 28 lines of actual code, which is only 10 more than the original, doesn’t require any supporting library and should work in any browser in use (and most that aren’t).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to do something like this? jQuery(selector).jQuery(subselector).command(....) My code is like this:
I'd like to ask if this 'synchronizing-scenario' is possible with php and javascript/jQuery... I
Using JQuery it possible to clone a Div like this and change add a
Is it possible to fill jQuery variable by PHP??? I mean something like this:
I'd like some help with the following jQuery code if possible... $(document).ready(function() { $('table.sortable').each(function()
I can run this code in Android app (using PhoneGap adn jQuery Mobile) but
I'm considering using this jquery utility as a possible solution, but I want to
I am wondering if it's possible to achieve this using the jQuery UI Slider.
for example, I want to add this to jsfiddle.net jQuery Validation is this possible?
Possible Duplicate: How to access this attribute using jquery, given a div defined by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.