WCAG Rule 17: No more than two h1 elements.

Rule Mapping

Markup References

Validation Code

Dependencies

None

Context

document

Parameters

None

Code

function (ruleContext) {
  var h1Nodes = ruleContext.getElementsByTagName("h1");
  var emptyH1Nodes = [];
  for (var i = 0; i < h1Nodes.length; ++i) {
    var h1Node = h1Nodes[i];
    if (util.getNodeTextRecursively(h1Node).length == 0) {
      emptyH1Nodes.push(h1Node);
    } // endif
  } // endfor
  var passed = (h1Nodes.length <= 1);
  return new ValidationResult(passed, h1Nodes, '', '', []);
}  // endfunction