Getting command argument in javascript

heika picture heika · Jul 27, 2012 · Viewed 8.1k times · Source

In the web page, I have some codes like

<span commandArgument="a">A</span>
<span commandArgument="b">B</span>

I want to use javascript to get the commandArgument values of the spans, and the code I wrote is

var spans = document.getElementsByTagName("span");
var value = spans[0].commandArgument;

It works in IE but fails in Firefox.
IE gets value = "a" and Firefox gets value = undefined.
Is there any method to get the values that works in both browser? Thanks!!

Answer

Ben picture Ben · Jul 27, 2012

Have you tried .getAttribute("commandArgument")?

...and its ugly cousin must be mentioned, .setAttribute("commandArgument", "c")