How to pass and get data in script tag in javascript Here is the code:
In "a1.html"
<script async="" data-id1="fordata1" data-id2="fordata2" data-id3="fordata3" data-id4="fordata4" data-id5="fordata5" src="get-id-in-js.js"></script>
In "get-id-in-js.js" file:
var scripts=document.getElementsByTagName("script");console.log(scripts[0].getAttribute("data-id1")); console.log(scripts[0].getAttribute("data-id2")); console.log(scripts[0].getAttribute("data-id3")); console.log(scripts[0].getAttribute("data-id4")); console.log(scripts[0].getAttribute("data-id5"));
0 comments:
Post a Comment