[Solved] Fetch a string between a static pattern in HTML [closed]


You could use DOMParser to convert the string to a document, after which you could querySelectorAll over it to find the elements with translate attributes:

const str = `<p translate="index_word1" > </p>
<strong translate="index_word2"></strong>`;
new DOMParser()
  .parseFromString(str, 'text/html')
  .querySelectorAll('[translate]')
  .forEach(element => console.log(element.getAttribute('translate')));

1

solved Fetch a string between a static pattern in HTML [closed]