-1

I am working on the below demo. Why am I not able to add id sample to the object? I am trying to control the element style through css but it is not working

var paper = Raphael("container", 500, 300); 
var dot = paper.circle(50, 50, 30).attr({ 
stroke: "#000", 
"stroke-width": 5 
}).data("id", "sample"); 
#sample{
  fill:red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<div id="container"></div>

2
  • Just a general note about brevity, Behseini. It looks like a large number of your posts are of the form "Can you please take a look at <thing> and let me know why <question>". This has a sort of needy, pleading feel for native English speakers, and is not the kind of technical, neutral writing we aim for here. I'd argue also that it is not ideal when one is addressing volunteers, since pleading is a form of emotional manipulation.
    – halfer
    Oct 24, 2020 at 20:53
  • You will find your posts are received generally better if you use "I" writing i.e. "I am doing [or working on] this <thing>" and "How can I / What can I do to achieve <thing>". I think the reason this works better is that it is better to show the reader that you know the bulk of the work is still yours to do. That is rather better than assuming the reader will take all your work from you (and relieve you of all your implied suffering). Thanks!
    – halfer
    Oct 24, 2020 at 20:55

1 Answer 1

1

The problem is data() doesn't refer to svg attributes on an element, but custom data on a Raphael element, that it can access.

If you want to set the id attribute, you would need to try one of the following...

set the 'id' within the attr({}) definition you are using (however, iirc some versions of Raphael don't work with that), if not you would need to do

dot.attr({ 'id', 'sample' }); // or try the following 

dot.node.setAttribute('id', 'sample'); // or 

dot.node.id = 'sample';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.