Skip to content

Instantly share code, notes, and snippets.

@hideki-a
Last active December 27, 2015 16:19
Show Gist options
  • Save hideki-a/7353743 to your computer and use it in GitHub Desktop.
Save hideki-a/7353743 to your computer and use it in GitHub Desktop.
label要素と対応するコントロールを表示させる試み。使い方は次のURLを参照:https://github.com/bgrins/devtools-snippets
// labelchecker.js
// Forked from formcontrols.js
// https://github.com/bgrins/devtools-snippets
// Print out label and their controls
(function() {
var forms = document.querySelectorAll("form");
for (var i = 0, len = forms.length; i < len; i++) {
var tab = [];
console.group("HTMLForm quot;" + forms[i].name + "quot;: " + forms[i].action);
console.log("Element:", forms[i], "\nName: " + forms[i].name + "\nMethod: " + forms[i].method.toUpperCase() + "\nAction: " + forms[i].action || "null");
["label"].forEach(function (control) {
[].forEach.call(forms[i].querySelectorAll(control), function (node) {
var forAttrVal = node.getAttribute("for");
var labelTargetElem;
var labelText;
if (!forAttrVal) {
return;
}
if (node.firstChild.nodeType === 3) {
labelText = node.firstChild.nodeValue;
} else {
labelText = "";
}
labelTargetElem = document.getElementById(forAttrVal);
tab.push({
"LabelText": labelText,
"ForAttributeValue": forAttrVal,
"TargetControl": labelTargetElem.tagName + "(name: " + labelTargetElem.name + ", value: " + labelTargetElem.value + ")"
});
});
});
console.table(tab);
console.groupEnd();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment