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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:13:14+00:00 2026-06-06T06:13:14+00:00

I have trouble with strange behavior of for..in cycle in JavaScript. I have the

  • 0

I have trouble with strange behavior of for..in cycle in JavaScript. I have the following HTML:

<div id="quarter_circle_top_left">...</div>
<div id="quarter_circle_top_right">...</div>
<div id="quarter_circle_bottom_right">...</div>
<div id="quarter_circle_bottom_left">...</div>    

<div id="author_dimension"></div>
<div id="similar_dimension"></div>
<div id="citation_dimension"></div>
<div id="concept_dimension"></div>

What I want is that when I hover over one of the “dimensions” (the latter 4 divs) one of the quarter circles (the first 4 divs) will be highlighted. I have the following enum in JS:

var DIMENSIONS = {
    DIM_AUTHORS: {value: 1, dimCode: "author_dimension", areaCode: "quarter_circle_top_left"},
    DIM_SIMILAR: {value: 2, dimCode: "similar_dimension", areaCode: "quarter_circle_top_right"},
    DIM_CITATIONS: {value: 3, dimCode: "citation_dimension", areaCode: "quarter_circle_bottom_right"},
    DIM_CONCEPTS: {value: 4, dimCode: "concept_dimension", areaCode: "quarter_circle_bottom_left"}
};

And this for..in cycle which should do the highlighting:

for (var key in DIMENSIONS) {
    $("#" + DIMENSIONS[key]['dimCode']).hover(
        function() {
            $("#" + DIMENSIONS[key]['areaCode']).addClass("hover");
        }, 
        function() {
            $("#" + DIMENSIONS[key]['areaCode']).removeClass("hover");
        }
    );
}

This sort of works but what happens is that the “dimensions” don’t highlight the respective quarter circle but instead hovering over any of them highlights only the last (bottom left) quarter circle. So when I hover over authors “dimension” I expect the top left quarter circle to be highlighted but instead only the last one (bottom left) is highlighted.

I tried to print the values of DIMENSIONS[key]['dimCode'] and DIMENSIONS[key]['areaCode'] and they are correct. Any ideas why my code doesn’t work as expected?

  • 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-06T06:13:16+00:00Added an answer on June 6, 2026 at 6:13 am

    As @Cranio says, it’s the loop/closure problem.

    Since you’re using jQuery, you can use $.each:

    $.each(DIMENSIONS, function(key, value) {
        // use value['dimCode'] instead of DIMENSIONS[key]['dimcode']
        ...
    });
    

    The introduction of the additional function scope avoids the loop/closure problem.

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

Sidebar

Related Questions

I have trouble parsing a HTML table using Nokogiri and Ruby. My HTML table
I have trouble finding a solution for the following problem: I have a lot
I have some strange behavior occurring in an ASP.NET application that I am trying
Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having some strange trouble with pamie: http://pamie.sourceforge.net/ . I have written a script
I am having a bit of trouble grabbing some files that have a strange
I have a strange trouble. I am not too familiar with Moq, being more
I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different
I have trouble where, for some reason, SVN would only merge the newly generated
I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish

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.