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-34.6.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.5.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.5.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.4.2 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.4.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.4.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.3.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.2.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.1.3 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.1.2 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.1.1 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.1.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-34.0.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-33.1.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs
govuk_publishing_components-33.0.0 node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs