Getting data attributes from script code using Javascript [duplicate]

Solution 1:

You could use document.querySelector() combined with the Attribute Selector to select the script like so

document.querySelector('script[data-text]').dataset.text