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.

Answers


Try this -

exampleelement.attr(attr_name, attr_value);

jQuery Docs - .attr()


Need Your Help

how use toggle button in item custom listView?

android

I want to use a custom ListView in my app..

xpath for a google search url issue no content

xpath

http://www.google.com/search?q=youtube

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.