Skip to content

Instantly share code, notes, and snippets.

@joekarma
Created August 20, 2013 14:27
Show Gist options
  • Save joekarma/6282093 to your computer and use it in GitHub Desktop.
Save joekarma/6282093 to your computer and use it in GitHub Desktop.
Extracting info on supported attributes for each element in the single page HTML5 spec.
var els = document.querySelectorAll("dl.element");
var attrsList = document.querySelectorAll("dl.element > dt > a[title^='element-'][title$='-attributes']");
function getItemsInAttrList(aList) {
var r = [];
r.push(aList.parentNode.parentNode.previousElementSibling.querySelector("code").textContent);
aList = aList.parentNode;
while (aList.nextElementSibling && aList.nextElementSibling.nodeName.toLowerCase() == "dd") {
r.push(aList.nextElementSibling.textContent);
aList = aList.nextElementSibling;
}
return r;
}
for (var i = 0; i < attrsList.length; i++) {
console.log(getItemsInAttrList(attrsList[i]));
}
/*
["html", "Global attributes", "manifest"]
["head", "Global attributes"]
["title", "Global attributes"]
["base", "Global attributes", "href", "target"]
["link", "Global attributes", "href", "crossorigin", "rel", "media", "hreflang", "type", "sizes", "Also, the title attribute has special semantics on this element."]
["meta", "Global attributes", "name", "http-equiv", "content", "charset"]
["style", "Global attributes", "media", "type", "scoped", "Also, the title attribute has special semantics on this element."]
["script", "Global attributes", "src", "type", "charset", "async", "defer", "crossorigin"]
["noscript", "Global attributes"]
["template", "Global attributes"]
["body", "Global attributes", "onafterprint", "onbeforeprint", "onbeforeunload", "onhashchange", "onmessage", "onoffline", "ononline", "onpagehide", "onpageshow", "onpopstate", "onresize", "onstorage", "onunload"]
["article", "Global attributes"]
["section", "Global attributes"]
["nav", "Global attributes"]
["aside", "Global attributes"]
["h1", "Global attributes"]
["header", "Global attributes"]
["footer", "Global attributes"]
["address", "Global attributes"]
["p", "Global attributes"]
["hr", "Global attributes"]
["pre", "Global attributes"]
["blockquote", "Global attributes", "cite"]
["ol", "Global attributes", "reversed", "start", "type"]
["ul", "Global attributes"]
["li", "Global attributes", "If the element is a child of an ol element: value"]
["dl", "Global attributes"]
["dt", "Global attributes"]
["dd", "Global attributes"]
["figure", "Global attributes"]
["figcaption", "Global attributes"]
["div", "Global attributes"]
["main", "Global attributes"]
["a", "Global attributes", "href", "target", "download", "rel", "hreflang", "type"]
["em", "Global attributes"]
["strong", "Global attributes"]
["small", "Global attributes"]
["s", "Global attributes"]
["cite", "Global attributes"]
["q", "Global attributes", "cite"]
["dfn", "Global attributes", "Also, the title attribute has special semantics on this element."]
["abbr", "Global attributes", "Also, the title attribute has special semantics on this element."]
["data", "Global attributes", "value"]
["time", "Global attributes", "datetime"]
["code", "Global attributes"]
["var", "Global attributes"]
["samp", "Global attributes"]
["kbd", "Global attributes"]
["sub", "Global attributes"]
["i", "Global attributes"]
["b", "Global attributes"]
["u", "Global attributes"]
["mark", "Global attributes"]
["ruby", "Global attributes"]
["rt", "Global attributes"]
["rp", "Global attributes"]
["bdi", "Global attributes", "Also, the dir global attribute has special semantics on this element."]
["bdo", "Global attributes", "Also, the dir global attribute has special semantics on this element."]
["span", "Global attributes"]
["br", "Global attributes"]
["wbr", "Global attributes"]
["ins", "Global attributes", "cite", "datetime"]
["del", "Global attributes", "cite", "datetime"]
["img", "Global attributes", "alt", "src", "crossorigin", "usemap", "ismap", "width", "height"]
["iframe", "Global attributes", "src", "srcdoc", "name", "sandbox", "seamless", "allowfullscreen", "width", "height"]
["embed", "Global attributes", "src", "type", "width", "height", "Any other attribute that has no namespace (see prose)."]
["object", "Global attributes", "data", "type", "typemustmatch", "name", "usemap", "form", "width", "height"]
["param", "Global attributes", "name", "value"]
["video", "Global attributes", "src", "crossorigin", "poster", "preload", "autoplay", "mediagroup", "loop", "muted", "controls", "width", "height"]
["audio", "Global attributes", "src", "crossorigin", "preload", "autoplay", "mediagroup", "loop", "muted", "controls"]
["source", "Global attributes", "src", "type", "media"]
["track", "Global attributes", "kind", "src", "srclang", "label", "default"]
["canvas", "Global attributes", "width", "height"]
["map", "Global attributes", "name"]
["area", "Global attributes", "alt", "coords", "shape", "href", "target", "download", "rel", "hreflang", "type"]
["table", "Global attributes", "border", "sortable"]
["caption", "Global attributes"]
["colgroup", "Global attributes", "span"]
["col", "Global attributes", "span"]
["tbody", "Global attributes"]
["thead", "Global attributes"]
["tfoot", "Global attributes"]
["tr", "Global attributes"]
["td", "Global attributes", "colspan", "rowspan", "headers"]
["th", "Global attributes", "colspan", "rowspan", "headers", "scope", "abbr", "sorted"]
["form", "Global attributes", "accept-charset", "action", "autocomplete", "enctype", "method", "name", "novalidate", "target"]
["fieldset", "Global attributes", "disabled", "form", "name"]
["legend", "Global attributes"]
["label", "Global attributes", "form", "for"]
["input", "Global attributes", "accept", "alt", "autocomplete", "autofocus", "checked", "dirname", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "height", "inputmode", "list", "max", "maxlength", "min", "multiple", "name", "pattern", "placeholder", "readonly", "required", "size", "src", "step", "type", "value", "width"]
["button", "Global attributes", "autofocus", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "menu", "name", "type", "value"]
["select", "Global attributes", "autofocus", "disabled", "form", "multiple", "name", "required", "size"]
["datalist", "Global attributes"]
["optgroup", "Global attributes", "disabled", "label"]
["option", "Global attributes", "disabled", "label", "selected", "value"]
["textarea", "Global attributes", "autocomplete", "autofocus", "cols", "dirname", "disabled", "form", "inputmode", "maxlength", "name", "placeholder", "readonly", "required", "rows", "wrap"]
["keygen", "Global attributes", "autofocus", "challenge", "disabled", "form", "keytype", "name"]
["output", "Global attributes", "for", "form", "name"]
["progress", "Global attributes", "value", "max"]
["meter", "Global attributes", "value", "min", "max", "low", "high", "optimum"]
["details", "Global attributes", "open"]
["summary", "Global attributes"]
["menu", "Global attributes", "type", "label"]
["menuitem", "Global attributes", "type", "label", "icon", "disabled", "checked", "radiogroup", "default", "command", "Also, the title attribute has special semantics on this element."]
["dialog", "Global attributes", "open"]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment