For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Thursday, January 19, 2023

pass and get data in script tag in javascript

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")); 

 

 

 

Share:

0 comments:

Post a Comment

Image Zoom Hover Effect

 Image Zoom Hover Effect                                                                   Image zoom hover out effect                      ...

Ads Inside Post

Powered by Blogger.

Arsip