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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:10:57+00:00 2026-05-26T15:10:57+00:00

I have made a div called navarea and inside it I have 6 more

  • 0

I have made a div called navarea and inside it I have 6 more div’s. When I mouse over I want to change there background color.

I dont want to have 6 mouse over functions for each div, instead I want to get the names of the divs from an array.

I can change the background colour without the mouseover function in this way, but as soon as I add the mouseover function it does absolutely nothing.

Thank you in advance for you help.

Bill

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script src="jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {



var mainnav=["dashboard","sales","marketing","production","accounts","logout"];


jQuery.each(mainnav, function() {

$("#" + this).mouseover(function(){ // Why is this line is failing?
$("#" + this).css("background-color","#8c9aa0");
});  

});


});
</script>

<style type="text/css">
#navarea {
height: auto;
width: 180px;
background-color:#FFF;
}

#dashboard {
height: auto;
width: 180px;
background-color:#FFF;
}


</style>
</head>

<body>
<div id="navarea">
<div id="dashboard">Dashboard</div>
<div id="sales">Sales</div>
<div id="marketing">Marketing</div>
<div id="production">Production</div>
<div id="accounts">Accounts</div>
<div id="logout">Logout</div>
</div>

</body>
</html>
  • 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-26T15:10:57+00:00Added an answer on May 26, 2026 at 3:10 pm

    You’re using the each function improperly. If the divs you want to target are within a parent element (for this example, let’s say the parent element is mainnav), then you should just do this:

    $("#mainnav").children().each(function(){
      $(this).hover(function(){
        $(this).css("background-color","#8c9aa0");
      }, function(){
        $(this).css("background-color","[insert mouseout color here]");
      });
    });
    
    1. The .hover() function lets you place both the mouseover and mouseout elements in the same function, as you can see above. This minimizes code.

    2. $("#" + this) makes no sense, as $(this) in jQuery selects the active element.

    3. I used the .children() function. All this does is select the elements nested within the selected element, in this case #mainnav.

    More about .each() here and more about .children() here.

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

Sidebar

Related Questions

I want to change the background color of the DIV depending on some true/false
I have a menu made of divs containers and when I mouse over the
I have a div element which is made jquery Resizable. It has alsoResize option
I have a simple nav made up of the following HTML; <div class=inner> <div
I have made a SVG image, or more like mini application, for viewing graphs
So I have made a clock, it works great. Now I want to move
I have about 12 div elements in a class called item i have used
I have made a table as below. <div class=grid_top_button> <div class=left_top_curve> &nbsp;</div> <div class=right_top_curve>
I have made a small xslt file to create an html output called weather.xsl
I have a buyer form, called Buyer.php: <form method=post action=check_buyer.php id=LoggingInBuyer> <div style=width:265px;margin:0; padding:0;

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.