jlg1987 jlg1987 - 8 months ago 12
Javascript Question

Raphael setting the attr of an element

I am using raphaeljs add need to set attributes on an element, however the attributes name and value are saved in variables

var attr_name='fill';
var attr_value='#343434';

but the following does not work

exampleelement.attr({attr_name: attr_value});

however if I type in the actual name in the attr field it works

exampleelement.attr({'fill': attr_value});

I have tried wrapping it in quotes and double quotes but this has no effect.

Please can anyone suggest anything?
It is not really an option to manually type them in as this code runs in a loop and each time it could be a different attribute it is setting.


Try this -

exampleelement.attr(attr_name, attr_value);

jQuery Docs - .attr()