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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:21:12+00:00 2026-05-22T23:21:12+00:00

Let me start by saying that this is working correctly, but I know it’s

  • 0

Let me start by saying that this is working correctly, but I know it’s not the most efficient way of coding it and I’m lacking the knowledge / understanding as to how to do this.

For this specific problem, i have 8 different events that are using a mouseover / mouseout function where it is hiding other classes that aren’t the said hover. I’m curious as to have it work for say an infinite amount of events with just a simple block of code.

Any help would be greatly appreciated. Here is my code thus far…

function hoverBar() {

     $(".song1result").mouseover(function(){
            $('.barReadout').not('.bar1').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar1').fadeTo('fast', 1.0, function() {});
    });

         $(".song2result").mouseover(function(){
            $('.barReadout').not('.bar2').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar2').fadeTo('fast', 1.0, function() {});
    });

         $(".song3result").mouseover(function(){
            $('.barReadout').not('.bar3').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar3').fadeTo('fast', 1.0, function() {});
    });

     $(".song4result").mouseover(function(){
            $('.barReadout').not('.bar4').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar4').fadeTo('fast', 1.0, function() {});
    });

         $(".song5result").mouseover(function(){
            $('.barReadout').not('.bar5').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar5').fadeTo('fast', 1.0, function() {});
    });

         $(".song6result").mouseover(function(){
            $('.barReadout').not('.bar6').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar6').fadeTo('fast', 1.0, function() {});
    });

         $(".song7result").mouseover(function(){
            $('.barReadout').not('.bar7').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar7').fadeTo('fast', 1.0, function() {});
    });

         $(".song8result").mouseover(function(){
            $('.barReadout').not('.bar8').fadeTo('fast', 0.1, function() {});
        }).mouseout(function(){
            $('.barReadout').not('.bar8').fadeTo('fast', 1.0, function() {});
    });
}

Thanks!! Matt

Edit:

I was lead to the correct answer from Shad’s response although it required a bit of tinkering.

Here’s my working solution:


function hoverBar2() {
    $('.songresult').mouseover(function(){
    var ID=$(this).attr('id').replace('#','');
    var ID2 = ID.replace('res','');

   $('.barReadout').not('#bre' + ID2).fadeTo('fast', 0.1, function() {}); 
}).mouseout(function(){
             var ID=$(this).attr('id').replace('#bre','');
        ///  alert(ID);
   $('.barReadout').not('#bre' + ID).fadeTo('fast', 1.0, function() {}); 
    });



}
  • 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-22T23:21:13+00:00Added an answer on May 22, 2026 at 11:21 pm

    If you have control of how the page content is rendered, then I would recommend moving the identifying numbers out of the classes and into the ids.
    e.g.

    <div class="songresult" id="res1"></div>
    <div class="barReadout" id="bre1"></div>
    

    This will allow you to write one block of code for all instances:

    $('.songresult').mouseover(function(){
        var ID=$(this).attr('id').replace(/\D/g,'');
       $('.barReadout').not('#bre' + ID).fadeTo('fast', 0.1, function() {}); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start by saying that I do not advocate this approach, but I
Let me start out by saying that I'm not a JavaScript developer so this
Let me begin by saying this; I know that similar questions exist, but they
First of all let me start by saying that this question is not about
Let me start off by saying that I am completely new with WPF (this
First off, let me start by saying that I am totally new to working
Let me start by saying that I'm not a power-JavaScript/jQuery programmer, I do very
Let me start off by saying that this is my first real Cocoa app.
Let me start by saying that I'm a linux guy and not really familiar
Let me preface this by saying that perhaps there's a better way to do

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.