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

The Archive Base Latest Questions

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

I have lots of rects automatically created on a Raphael canvas, for simplicity this

  • 0

I have lots of rects automatically created on a Raphael canvas, for simplicity this code only uses two:

for (i = 0; i < 2; ++i) {
    var square = paper.rect(0 + 100*i, 0, 70, 70);
    square.node.setAttribute('id', '_' + i);
    square.node.setAttribute('class', 'foo');
}

which creates this chunk below (as seen with view selection source in Firefox):

<svg height="560" width="560" version="1.1" xmlns="http://www.w3.org/2000/svg"><desc>Created with Raphael</desc><defs></defs><rect class="foo" id="_0" stroke="#000" fill="none" ry="0" rx="0" r="0" height="70" width="70" y="0" x="0"></rect><rect class="foo" id="_1" stroke="#000" fill="none" ry="0" rx="0" r="0" height="70" width="70" y="0" x="100"></rect></path></svg>

The css class indicates the color to fill. I would like to change the class of the each rect, individually, using a click function. I would need something like:

function change_class() {
    //something here
}

From everything I’ve read, this is done using .node , but here I don’t have a separate variable for each rect, given that square was overwritten on each iteration of the for() loop.

One way to do this would be to push all rects to an array, like this:

squares = [];
for (i = 0; i < 2; ++i) {
    var square = paper.rect(0 + 100*i, 0, 70, 70);
    square.node.idx = i;
    square.node.setAttribute('class', 'foo');
    squares.push(square);
}

I could then change the class directly via:

squares[0].node.setAttribute('class', 'other');

BUT… I still don’t know how to do it via the general function change_class()… I need something like:

$('rect').click(function() {
    change_class(); // the click function should pass "$(this)" to change_class ?
});

What would be the right jQuery + Raphael method to do this?

Thanks in advance,
Adrian

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

    If you want to click the box itself to change its color, you don’t need jQuery, you can use Raphael’s built-in event method, and refer to the rectangle as this, like so:

         rect.click( function () {
            this.node.setAttribute('class', 'newClass');
         });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lots of code like this: FileStream fs = File.Open(@C:\Temp\SNB-RSS.xml, FileMode.Open); using (XmlTextReader
I have lots of pdf documents to merge together, so I wrote this code
I have lots of text marked up like this: <span class=section>[<a href=blablabla>Section</a>]</span> I need
I have lots of variables in an array like this: short num = 7123;
i have lots of videos in my server and i use the following code
I have lots of few small functions, each executes a query. I want only
i have lots of data like this 1:0x00a4c7d9fb3849... 2:0x79821309bd789c7689c97... 3:0x0178dce67fe898... they are more than
I have lots of folders and each of them contains two files: one is
I have lots of data like this type1, type2, type3 aax, ert, ddd asx,
I have lots of source code files. I have lots of hard coded string.

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.