New Jan 13, 2026

`document.currentScript` is more useful than I thought.

More Front-end Bloggers All from Frontend Masters Boost RSS Feed View `document.currentScript` is more useful than I thought. on frontendmasters.com

Huh. Today I learned (from Alex MacArthur): you can access the current <script> element from a script (if it’s not type="module") with document.currentScript. Meaning you can put configuration data as attributes on it and pluck them off and use them. Like:

<h1 id="setMePlease"></h1>

<script data-some-value="foo">
  const scriptData = document.currentScript.dataset;
  setMePlease.textContent = scriptData.someValue;
</script>
Scroll to top