Rodger
Rodger

Reputation: 143

How to list all element attributes in JS?

I would like to know all possible attributes of an element in JS.

I did :

s = document.getElementById("idSvg");

r = s.attributes;

alert(r.length);

...
...
<svg width="450" height="250" id="idSvg">
...
</svg>

But the result is 3. Seems to be the number of attributes I use (width, height and id), but I would like to list ALL the possible attributes an SVG element may have.

Thanks for helping, Rodg

Upvotes: 3

Views: 2803

Answers (3)

mplungjan
mplungjan

Reputation: 178413

http://www.w3.org/TR/SVG/attindex.html

baseProfile class contentScriptType contentStyleType externalResourcesRequired height id onabort onactivate onclick onerror onfocusin onfocusout onload onmousedown onmousemove onmouseout onmouseover onmouseup onresize onscroll onunload onzoom preserveAspectRatio requiredExtensions requiredFeatures style systemLanguage version viewBox width xml:base xml:lang xml:space x y zoomAndPan

Upvotes: 1

Kris Ivanov
Kris Ivanov

Reputation: 10598

you can try this, but better off looking it up on w3.org

(function() {
    var s = document.getElementById("idSvg");

    for (var key in s) {
        document.write(key + "<br />");
    }
})();

Upvotes: 1

Nicolas Goy
Nicolas Goy

Reputation: 1430

I don't think it is possible, as JS have no clue whatsoever about DTD format. You need to look at the tag specification (taking into account the proper doctype that tag will be used in).

Upvotes: 2

Related Questions