-1

How do I define and pass a value to a script tag from the html file?

for example to do something like below where I want to pass the value of "myparameter"

<script src="app.js" myparameter="myvalue" type="module"></script>
draca
  • 1,319
  • 5
  • 16
  • 32

1 Answers1

0

If you have your html like this:

<script src="app.js" myparameter="myvalue" type="module"></script>

Inside js script:

document.currentScript.getAttribute('myparameter'); //myvalue
ICK56
  • 34
  • 4
  • 3
    This is clearly a duplicate; to better maintain the quality of the site, please don't answer and vote/flag as such (if you have the privilege). – esqew Nov 10 '21 at 12:38