0

How can I console.log the data-text value in that javascript file? Noob here still learning. Thanks for the help or information..

Sample: <script type="text/javascript" src="./test.js" data-text="Hello World"></script>

Maharlikan
  • 63
  • 7

1 Answers1

1

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

document.querySelector('script[data-text]').dataset.text
caramba
  • 21,963
  • 19
  • 86
  • 127