3

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

0

3 Answers 3

2

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).

Sign up to request clarification or add additional context in comments.

Comments

1

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 />");
    }
})();

3 Comments

this seems not differ attribute from property, is there a better way to filter only attribute out?
all are treated as properties, you can make distinction however if it is local or inherited property, here is an example jsfiddle.net/5CGNR
Faster : console.dir(document.getElementById("idSvg"));
1

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.