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

  • Home
  • SEARCH
  • 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 7567443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:39:54+00:00 2026-05-30T14:39:54+00:00

I am creating sliding menus in JavaScript, and the following is my init() function:

  • 0

I am creating sliding menus in JavaScript, and the following is my init() function:

function init() {
   var menus = new Array();
   var allElems = document.getElementsByTagName("*");

   for (var i = 0; i < allElems.length; i++) {
      alert(allElems[i]);
      if (allElems[i].className == "navG") {
      alert(allElems[i]);
      menus.push(allElems[i]); 
      }
   }

   /* assign the openMenu function to the onclick event for each
      Menus item */
    for (var i = 0; i < menus.length; i++) {
       alert(menus[i]);
       menus[i].onclick=openMenu;
    }

    document.getElementById("logo").onclick = closeMenu;
    document.getElementById("linkList").onclick = closeMenu;
    document.getElementById("main").onclick = closeMenu;
}

The problem seems to be in the first for loop. This is definitely the correct class name..just for reference, this is the type of HTML that I am referring to:

<div class="navG" id="gallery1" style="position: absolute; top: 180px; left: -150px; " >

Is there an obvious, or not so obvious reason, that this is not adding the elements to menus?

  • 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-05-30T14:39:55+00:00Added an answer on May 30, 2026 at 2:39 pm

    In the page you linked to, in your family.js script, this line:

    window.onLoad = init();
    

    says to run the init function immediately and assign its return value to window.onLoad. Because it is running immediately the actual document hasn’t been parsed yet so it doesn’t find any of your elements. You need to say this:

    window.onload = init;
    

    which assigns a reference to the init function to window.onload so that that function will be run later after all of the elements have been parsed.

    Also onload should have a lowercase l.

    (There are some other problems in your code, e.g., you don’t seem to have elements with the ids "linkList" or "main", but I think what I said above is the main problem with the part you are asking about.)

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

Sidebar

Related Questions

Creating a document fragment using plain Javascript is dead simple: var docFragment = document.createDocumentFragment();
I'm creating a new slider that will integrate with my self written Javascript library.
Creating a click event for an input is easy $('input').click(function () { alert('adsf'); });
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
I am relatively new to using jQuery and I have a problem with creating
Creating Trial .git -repo $ mkdir Test; cd Test; git init $ echo Just
I have a problem with creating a sliding puzzle. I'm trying to make a
Creating function to print question, add choices to a list. def print_et_list (): answer_list
I am not very familiar with java-script/ jquery. i am creating a sliding social
I'm creating a simple sliding motion. But the div that is sliding in is

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.