In this post I will provide a trick to pass data to embedded JavaScript or external JavaScript files.
Passing Data
Data can be passed simply using data-* attributes in script tags.
Retrieving Data
Data can be retrieved by obtaining a reference to the script tag and then reading the data-* value. Reference to the current script can be obtained using document.currentScript property.
Leave a Reply