Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pass value inside the js file using script tag

I came across an idea as assigning an id to the <script> element and 
passing the arguments as data-* attributes. The resulting <script> tag would 
look something like this:

<script id="helper" data-name="helper" src="helper.js"></script>

The script could then use the id to programmatically locate itself and parse 
the arguments. Given the previous <script> tag, the name could be retrieved 
like this:

var name = document.getElementById("helper").getAttribute("data-name");

We get output name = helper
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add jquery to an html css and javascript project 
Javascript :: check install modules npm directory 
Javascript :: truthy and falsy js 
Javascript :: javascript array destructuring 
Javascript :: jquery numeric validation 
Javascript :: jquery datatable server side pagination asp.net core 
Javascript :: jquery is not defined error in wordpress 
Javascript :: apollo client mutation without component 
Javascript :: ajax call to load a page on scrolling 
Javascript :: delete in array 
Javascript :: npm node size 
Javascript :: jquery onchange get element 
Javascript :: call a javascript function at a specific time of day 
Javascript :: await the end of subscribe angular 
Javascript :: js localstorage clear 
Javascript :: if syntax javascript 
Javascript :: how to decode jwt token in react 
Javascript :: write files in Node.js 
Javascript :: js round to x decimal places 
Javascript :: promise.all jquery ajax 
Javascript :: js slice 
Javascript :: jquery get search parameter 
Javascript :: promise 
Javascript :: infinite carousel javascript 
Javascript :: push method in javascript 
Javascript :: events in javascript 
Javascript :: barcode scanner react js 
Javascript :: add class to new element javascript 
Javascript :: javascript switch items in array 
Javascript :: how to remove link in image in jquery 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =