Sha256: ac09319a7d1d656372b4ba965f9aad8dfa14c73bced7bd35db0c810ef888bcb5

Contents?: true

Size: 807 Bytes

Versions: 375

Compression:

Stored size: 807 Bytes

Contents

/* global dom */

/**
 * Returns a reference to the element matching the attr URL fragment value
 * @method getElementByReference
 * @memberof axe.commons.dom
 * @instance
 * @param {Element} node
 * @param {String} attr Attribute name (href)
 * @return {Element}
 */
dom.getElementByReference = function(node, attr) {
	let fragment = node.getAttribute(attr);
	if (!fragment) {
		return null;
	}

	if (fragment.charAt(0) === '#') {
		fragment = decodeURIComponent(fragment.substring(1));
	} else if (fragment.substr(0, 2) === '/#') {
		fragment = decodeURIComponent(fragment.substring(2));
	}

	let candidate = document.getElementById(fragment);
	if (candidate) {
		return candidate;
	}

	candidate = document.getElementsByName(fragment);
	if (candidate.length) {
		return candidate[0];
	}
	return null;
};

Version data entries

375 entries across 375 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/dom/get-element-by-reference.js