Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: get the current executing <script> node? [duplicate]

Tags:

javascript

dom

I need to know if it is possible to obtain the current execution node?

Example:

..html <script id="x">   console.log(document.currentNode.id); // << this must return "x" </script> ..html 

Thanks!

like image 320
Martin Borthiry Avatar asked Jun 02 '10 03:06

Martin Borthiry


People also ask

What is __ dirname Nodejs?

__dirname: It is a local variable that returns the directory name of the current module. It returns the folder path of the current JavaScript file.

How do I get the current path in node JS?

We can get the path of the present script in node. js by using __dirname and __filename module scope variables. __dirname: It returns the directory name of the current module in which the current script is located. __filename: It returns the file name of the current module.

What is process CWD?

process. cwd() returns the current working directory, i.e. the directory from which you invoked the node command. __dirname returns the directory name of the directory containing the JavaScript source code file.

What is the purpose of __ filename variable?

To get the absolute path of the current file/code. To get the name of the file currently executing.


1 Answers

Modern browsers support a standard property on document object that points to the current script node:

https://developer.mozilla.org/en-US/docs/DOM/document.currentScript

<script id="x">   console.log(document.currentScript.id); // << this must return "x" </script> 
like image 121
ming_codes Avatar answered Sep 22 '22 01:09

ming_codes