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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:23:33+00:00 2026-05-27T14:23:33+00:00

Based on Raphael demo: http://raphaeljs.com/australia.html I have created objects that changes their colour. But

  • 0

Based on Raphael demo: http://raphaeljs.com/australia.html I have created objects that changes their colour. But I need to add action onclick will change it colour (to orange). And then it will stay orange until it will be clicked again.

I want those objects to show selected state (by having different colour). If you click on object it changes colour. If you click again it goes back to normal. And again If you click it changes colour and shows that is selected.

This is part of my code:

            var current = null;
        for (var state in bodyParts) {
            bodyParts[state].color = Raphael.getColor();
            (function (st, state) {
                st[0].style.cursor = "pointer";
                st[0].onmouseover = function () {
                    current && bodyParts[current].animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500) && (document.getElementById(current).style.display = "");
                    st.animate({ fill: st.color, stroke: "#ccc" }, 500);
                    st.toFront();
                    R.safari();
                    document.getElementById(state).style.display = "block";
                    current = state;
                };
                st[0].onmouseout = function () {
                    st.animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500);
                    st.toFront();
                    R.safari();
                };
                st[0].onclick = function () {
                    st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
                    st.toFront();
                    R.safari();
                };                    
            })(bodyParts[state], state);

Onclick it changes colour but after I take mouse out from object it comes back to normal and is not selected. How can I add this ‘selected’ behavior to this code?

  • 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-27T14:23:34+00:00Added an answer on May 27, 2026 at 2:23 pm

    Add another parameter that keeps the selected state.

       st[0].state = 0;
    

    Modify this:

                st[0].onclick = function () {
                    st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
                    st.toFront();
                    R.safari();
                };
    

    Like this:

                st[0].onclick = function () {
                    st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
                    st.toFront();
                    if (this.state == 0)
                       this.state = 1;
                    else
                       this.state = 0;
                    R.safari();
                };
    

    And this:

                st[0].onmouseout = function () {
                    st.animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500);
                    st.toFront();
                    R.safari();
                };
    

    Like this:

                st[0].onmouseout = function () {
                    if (this.state == 0)
                       st.animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500);
                    else
                       st.animate({ fill: "#f00", stroke: "#E0B6B2" }, 500);
                    st.toFront();
                    R.safari();
                };
    

    Of course, with your colors… but that’s the main idea.

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

Sidebar

Related Questions

Based on the http://www.mssqltips.com/sqlservertip/2597/dataset-and-tablix-filtering-in-sql-server-reporting-services/ , I created a dataset in a SSRS report which
Based on http://developer.android.com/guide/topics/data/data-storage.html#db it seems like I'd need another Java Class file (which I
Based on this article http://www.codeproject.com/KB/linq/bindinglist_sortable.aspx I implemented my bussines object with sortable feature. When
based on Join MS Word documents I have made a console application that splices
Based on http://www.thinkingguy.net/2010/01/localizing-labelfor-in-aspnet-mvc-2.html I'm trying to use reflection to get to a string property
I have RaphaelJS based canvas, where user can do some work. I need to
Based on http://tutorialzine.com/2011/06/beautiful-portfolio-html5-jquery/ tutorial I am trying to implement a sort function to my
Based on the manual as follows: http://api.jquery.com/attr/ attr( attributeName, value ) I should be
Based on their work, how do you distinguish a great SQL developer? Examples might
Based on the response to this question: Why does C++ have header files and

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.