diff --git a/src/index.js b/src/index.js index 30820b6..864a1aa 100644 --- a/src/index.js +++ b/src/index.js @@ -44,8 +44,8 @@ const sourceselector = (element) => { formElementSelector = element.tagName === 'INPUT' ? `form input[type='${element.getAttribute('type')}']` : `form ${element.tagName.toLowerCase()}`; } + const blockName = element.closest('.block') ? element.closest('.block').getAttribute('data-block-name') : ''; if (element.id || formElementSelector) { - const blockName = element.closest('.block') ? element.closest('.block').getAttribute('data-block-name') : ''; const id = element.id ? `#${element.id}` : ''; return blockName ? `.${blockName} ${formElementSelector}${id}` : `${formElementSelector}${id}`; } @@ -53,6 +53,11 @@ const sourceselector = (element) => { if (element.getAttribute('data-block-name')) { return `.${element.getAttribute('data-block-name')}`; } + + if (Array.from(element.classList).some((className) => className.match(/button|cta/))) { + return blockName ? `.${blockName} .button` : '.button'; + } + return sourceselector(element.parentElement); };