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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:48:57+00:00 2026-06-07T07:48:57+00:00

I need a little help consolidating my code. This is the working code but

  • 0

I need a little help consolidating my code. This is the working code but I can’t seem to get it when I try and simplify.

I wrote it with jquery and I’ve new to javascript as a whole. It’s basically a loop but I’m not sure how to loop it through.

<script type="text/javascript">
// house_one
    $('.house_one')
    .mouseenter(function() {
      $('.box_one').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_one').removeClass('hover');
    });
    $('.box_one')
    .mouseenter(function() {
      $('.house_one').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_one').removeClass('house_hover');
    });
//house_two
    $('.house_two')
    .mouseenter(function() {
      $('.box_two').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_two').removeClass('hover');
    });
            $('.box_two')
    .mouseenter(function() {
      $('.house_two').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_two').removeClass('house_hover');
    });
// house_three
    $('.house_three')
    .mouseenter(function() {
      $('.box_three').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_three').removeClass('hover');
    });
    $('.box_three')
    .mouseenter(function() {
      $('.house_three').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_three').removeClass('house_hover');
    });
// house_four
    $('.house_four')
    .mouseenter(function() {
      $('.box_four').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_four').removeClass('hover');
    });
    $('.box_four')
    .mouseenter(function() {
      $('.house_four').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_four').removeClass('house_hover');
    });
// house_five
    $('.house_five')
    .mouseenter(function() {
      $('.box_five').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_five').removeClass('hover');
    });
    $('.box_five')
    .mouseenter(function() {
      $('.house_five').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_five').removeClass('house_hover');
    });
// house_six
    $('.house_six')
    .mouseenter(function() {
      $('.box_six').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_six').removeClass('hover');
    });
    $('.box_six')
    .mouseenter(function() {
      $('.house_six').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_six').removeClass('house_hover');
    });
// house_seven
    $('.house_seven')
    .mouseenter(function() {
      $('.box_seven').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_seven').removeClass('hover');
    });
    $('.box_seven')
    .mouseenter(function() {
      $('.house_seven').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_seven').removeClass('house_hover');
    });
// house_eight
    $('.house_eight')
    .mouseenter(function() {
      $('.box_eight').addClass('hover');
    })
    .mouseleave(function() {
      $('.box_eight').removeClass('hover');
    });
    $('.box_eight')
    .mouseenter(function() {
      $('.house_eight').addClass('house_hover');
    })
    .mouseleave(function() {
      $('.house_eight').removeClass('house_hover');
    });
</script>
  • 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-07T07:48:58+00:00Added an answer on June 7, 2026 at 7:48 am
    function setupHovers(house, box){
        house = $(house);
        box   = $(box);
        house.hover(function(){  box.toggleClass('hover');  });
        box.hover(function(){    house.toggleClass('house_hover');  });
    }
    
    boxHouseArray = ['one','two','three','four','five','six' ...]; //
    
    for(boxHouse in boxHouseArray){
       setupHovers('.house_'+boxHouse, '#box_'+boxHouse);
    }
    

    or even better change your markup slightly:

    <a href="/interiors/house_1" class="house_list">House 04</a>
     and
    <div class="box"></div>
    

    now you can go like this:

    var houses = $('.house_list'), boxes = $('.box');
    houses.hover(function(){
        boxes.eq( houses.index(this) ).toggleClass('hover'); 
    });
    boxes.hover(function(){
        houses.eq( boxes.index(this) ).toggleClass('house_hover'); 
    });
    

    The idea here is no extra id’s or markup, we simply use the order of the elements in the markup as our configuration. Lets say we mouse over the first box: index(this) will tell us if its the first box on the page and trigger the hover class on the first house via eq

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

Sidebar

Related Questions

Need a little help with this script. It's working but I'd love a way
I need a little help getting this jQuery plugin to work correctly for me.
I need a little help here. This code correctly displays every format I enter--except
I need a little help with the fsockopen function. I have this PHP code:
I need a little help positioning a div correctly. This is my code: <td
I would need little help here. I'm trying to get the git respository from
Need a little help with my jquery here I want all my button with
I need a little help getting this script doing what I want it to.
I need little help with inheritance in C++. I have code with same structure
need a little help with this one. I have a form that I am

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.