I am trying to add data-client-key in my dynamically created JavaScript attribute. Check below code what I have tried:
var script = document.createElement("script")
script.type = "text/javascript";
script.src = 'https://app.example.com/snap/script.js';
//script.data-client-key="CLIENT-KEY-HERE"; /* showing error message */
document.getElementsByTagName(script)[0].setAttribute("data-client-key", "CLIENT-KEY-HERE"); /* Uncaught TypeError: Cannot read property 'setAttribute' of undefined */
document.getElementsByTagName("head")[0].appendChild(script);
My output should be like below when I inspect element:
<script src="https://app.example.com/snap/script.js" data-client-key="CLIENT-KEY-HERE"></script>