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 111451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:23:15+00:00 2026-05-11T02:23:15+00:00

I already started this in javascript so I don’t want to use jquery but

  • 0

I already started this in javascript so I don’t want to use jquery but can somejavascript expert look at my code and tell me what I’m doing wrong and or right? Let me tell you what I am trying to accomplish here. I have a menu that consists of four buttons and when you hover over them, they change color and then underneath a heading image is displayed when you hover over the heading, the button should go back to its original color, and then underneath the heading appears another image that contains some text. For the most part the code works ok except in Firefox sometimes the headings shift around and I am assuming that this is because when visible the text image doesn’t exist, so the heading falls to where the text would be, I don’t have this problem in IE. The biggest problem is the onmouseout. I don’t want the original button to go back to the color right away because I need time to be able to roll over the heading to show the text, so I was trying to use a setTimeout function to pause for a few seconds but it didn’t work.

Here’s the code:

window.onload = rollover; function rollover() var images = document.getElementsByTagName('img'); // Get all the images in the document var roll = new RegExp('roll'); var preload = []; var fileLoc = 'images/rollovers/'; for ( var i=0; i<images.length; i++)  {     if (images[i].id.match(roll)) // Loop through all the images in document and look for match on 'roll'     {         preload[i] = new Image();         preload[i].src = fileLoc + images[i].id + '_over.gif'; // Preload the _overs into an array.         images[i].onmouseover = function()  // Add a mouseover event to image         {             this.src = fileLoc + this.id + '_over.gif'; // When rolled over, this file now equals the _over image             var currentButton = this.id; // Grab the id of the current image             var imageHeader = document.getElementById('current_title'); //Grab all images that are titled 'current_title'             var newHeaderImage = new Image();             newHeaderImage.src = fileLoc + currentButton + '_header.gif'; // Create new image and store _Header image inside             newHeaderImage.id = currentButton + '_header'; //New id for new image is file + headerId             imageHeader.src = newHeaderImage.src;             imageHeader.height = newHeaderImage.height; // Assign header image id to currect location             imageHeader.width = newHeaderImage.width;             imageHeader.style.visibility = 'visible';             imageHeader.onmouseover = function() // Attach mouse event for header image             {                 var imageText = document.getElementById('button_text');                 var newTextImage = new Image();                 newTextImage.src = fileLoc + currentButton + '_text.gif';                 imageText.src = newTextImage.src;                 imageText.height = newTextImage.height;                 imageText.width = newTextImage.width;                 imageText.style.visibility = 'visible';              }           }         //images[i].onmouseout = setTimeout(mouseOut(fileLoc, this.id),3000);     }     } 

}

/*function mouseOut(fileLoc, curButton) 

{

var titleImg = document.getElementById('current_title'); var imgButton = curButton; this.src = fileLoc + imgButton + '_org.gif';  titleImg.style.visibility = 'hidden'; 

}*/

  • 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. 2026-05-11T02:23:15+00:00Added an answer on May 11, 2026 at 2:23 am

    Ok, here’s a script that works (at least in ie and firefox) that doesn’t use libraries.
    Using a library would obviously make this code a lot more succinct.

    window.onload = createRollover;  function createRollover() {     var button;     var imgPath = 'img/';     var container = document.getElementById( 'ro_container' );     var buttonContainer = document.getElementById( 'ro_buttons' );     var headerContainer = document.getElementById( 'ro_header' );     var textContainer = document.getElementById( 'ro_text' );     var buttons = buttonContainer.getElementsByTagName( 'img' );      container.onmouseout = rollOut;      // set up the element hierarchy     for( var i = 0; i < buttons.length; i++ ) {         button = buttons[i];         button.onmouseover = buttonRollover;         button.up =  document.createElement( 'img' );         button.up.src = imgPath+button.id+'.gif';         button.over =  document.createElement( 'img' );         button.over.src = imgPath+button.id+'_over.gif';         button.header = document.createElement( 'img' );         button.header.src = imgPath+button.id+'_header.gif';         button.header.onmouseover = headerRollover;         button.header.text =  document.createElement( 'img' );         button.header.text.src = imgPath+button.id+'_text.gif';     }      function buttonRollover() {          //do nothing if this button is already active         if( this.src == this.over.src ) return;          //reset all the buttons and set this one to over         for( var i = 0; i < buttons.length; i++ ) {             buttons[i].src = buttons[i].up.src;         }         this.src = this.over.src;          //see what's in the header div and do the header thing         var h = headerContainer.getElementsByTagName( 'img' );         if( h.length > 0 ) {             headerContainer.replaceChild( this.header, h[0] );         } else {             headerContainer.appendChild( this.header );         }         //clear the text div         textContainer.innerHTML = '';     }      function headerRollover() {         //see what's in the text div and do the thing         var t = textContainer.getElementsByTagName( 'img' );         if( t.length > 0 ) {             textContainer.replaceChild( this.text, t[0] );         } else {             textContainer.appendChild( this.text );         }     }      function rollOut( e ) {         //mouseouts take a bit of work         //that's one of the reasons why we like libraries         e = e || window.event;         var onto = e.relatedTarget || e.toElement;         // we'll cancel this event if we've rolled on to an element         // that is a child of this one.         // traverse up the tree looking for 'this' or the document         while( onto != this && onto != document ) {             onto = onto.parentNode;         }         if( onto == this ) {             //false alarm, it was a child of 'this'             return;          }         // reset         for( var i = 0; i < buttons.length; i++ ) {             buttons[i].src = buttons[i].up.src;         }         headerContainer.innerHTML = '';         textContainer.innerHTML = '';     } }  

    And the markup

    <div id='ro_container'>     <div id='ro_buttons'>         <img src='img/but1.gif' id='but1'/>         <img src='img/but2.gif' id='but2'/>         <img src='img/but3.gif' id='but3'/>     </div>     <div id='ro_header'></div>     <div id='ro_text'></div> </div> 

    I used the same image naming system you did (I think):

    but1.gif, but1_over.gif, but1_header.gif, but1_text.gif   but2.gif.... 

    Hope this helps

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There could be many reasons why but I am guessing… May 11, 2026 at 11:04 am
  • added an answer Found the right way of doing it. As the documentation… May 11, 2026 at 11:04 am
  • added an answer With the latest version of ASP.NET MVC (the RC, at… May 11, 2026 at 11:04 am

Related Questions

I already started this in javascript so I don't want to use jquery but
Im looking to build a thread manager for an application. I have already started
I've recently started with Python, and am enjoying the batteries included design. I'e already
OK, I know there have already been questions about getting started with TDD ..
I already know how to: Load properties files into my Spring configuration using: <context:property-placeholder
I already know the obvious answer to this question: just download <insert favorite windows
I already know Java, Objective C, C#, and some Python. I want to be
I already have a deploy.rb that can deploy my app on my production server.
I already asked this question at the JOS-.NET board but Joel is closing that
I already used a hidden file upload control to browse file and grab the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.