Search code examples
javascriptuserscriptshtml

How to know the possible HTML attributes of an element (EG <img>) in JS?


How to know the possible HTML attributes of an element (EG ) in JS?

How can I get to know a list of possible HTML attributes for a particular HTML node?

For example, when writing a userscript, I would like to know the possible HTML attributes of such nodes:

var images = d.getElementsByTagName('img');

something like: images[i].src


Solution

  • Browsers do not expose that information. You would need to get or create a machine readable specification for the markup language you are using.

    HTML 4, for example, has DTDs that you could parse: