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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:27:55+00:00 2026-06-09T00:27:55+00:00

So I have a strange problem with the raphael.js library that makes no sense

  • 0

So I have a strange problem with the raphael.js library that makes no sense to me. I have a map of the world with dots representing locations. Many of the dots overlap each other. When I want to single out various locations I would like to brint the element to the foreground.

Given the following code…

$("#peerIdSelector").change(function() {
    var peerSelected = $(this).val();
    var counter = 0;
    var antiCounter = 0;
    paper.forEach(function (el) {
        var peer = el.data("peer");
        if (peer === peerSelected) {
            //el.toFront();
            el.attr("fill", "#ffff00");
            counter++;
         } else {
            el.attr("fill", "#00ffff" );
            antiCounter++;
         }
    });
    alert(counter + " peers updated for " +  peerSelected + "\n" + antiCounter + " peers not updated")
});

When the el.toFront() is commented out, the code works as expected, finding the correct number of elements based on the if statement. However if I include the el.toFront() directive, then only the first if (peer === peerSelected) encountered will show as true, every other one after that shows up as false.

At the moment I’m stumped as to what would cause this behavior. What am I doing wrong here?

  • 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-09T00:27:56+00:00Added an answer on June 9, 2026 at 12:27 am

    This is what Raphael’s forEach function does:

    paperproto.forEach = function (callback, thisArg) {
        var bot = this.bottom;
        while (bot) {
            if (callback.call(thisArg, bot) === false) {
                return this;
            }
            bot = bot.next;
        }
        return this;
    };
    

    Calling toFront on the current item will cause the element is in question to be moved to the end of the list, so bot.next will be null and the while loop will kick out earlier than you intended.

    I’d recommend this as a solution:

    var frontSet = paper.set();
    paper.forEach(function (el) {
        var peer = el.data("peer");
        if (peer === peerSelected) {
            frontSet.push( el );
            el.attr("fill", "#ffff00");
            counter++;
         } else {
            el.attr("fill", "#00ffff" );
            antiCounter++;
         }
    });
    frontSet.toFront();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem getting the color of the point that was touched.
I have a strange problem: I have a CSV file that I read correctly
I have a strange problem that I've never encountered before, I have data in
I have a strange problem that I can't get my head around: I have
Have a strange problem in that I have a Rake task that seems to
I have a strange problem with mod_rewrite, the rules that are relevant here are:
I have a strange problem in my project. I have a class that inherits
I have a strange problem that's happening with my WCF REST service. For an
I have a strange problem with buttons that are next to an input field,
I have a strange problem in Fiddler that I have been unable to fix

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.