Sha256: 926a9a07d99590e9eab031eff3542bb0f517a8dc4a30742f84be48c797175ded

Contents?: true

Size: 609 Bytes

Versions: 35

Compression:

Stored size: 609 Bytes

Contents

import '../vendor/polyfills/Element/prototype/closest.mjs'

/**
 * Returns the value of the given attribute closest to the given element (including itself)
 *
 * @param {HTMLElement} $element - The element to start walking the DOM tree up
 * @param {string} attributeName - The name of the attribute
 * @returns {string | undefined} Attribute value
 */
export function closestAttributeValue ($element, attributeName) {
  var closestElementWithAttribute = $element.closest('[' + attributeName + ']')
  if (closestElementWithAttribute) {
    return closestElementWithAttribute.getAttribute(attributeName)
  }
}

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
govuk_publishing_components-35.3.3 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.3.2 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.3.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.3.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.2.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.1.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.1.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-35.0.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.14.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.13.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.12.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.11.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.10.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.10.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.9.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.9.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.8.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.8.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.7.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.7.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs