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>
More Related Contents:
- jQuery. Find all attribute values within/under elements `script or noscript or iframe` that have attribute keys as `src or href` [closed]
- When I load the page the alert(“hey”) function appears, why does the js function execute despite no onClick call? How do I prevent it from doing so?
- If a DOM Element is removed, are its listeners also removed from memory?
- What is the most efficient way to create HTML elements using jQuery?
- How can I check if an element exists in the visible DOM?
- Can scripts be inserted with innerHTML?
- What is offsetHeight, clientHeight, scrollHeight?
- How can I get the DOM element which contains the current selection?
- How to avoid the need for ctrl-click in a multi-select box using Javascript?
- How do I programmatically click on an element in JavaScript?
- Difference between DOM parentNode and parentElement
- How to access component methods from “outside” in ReactJS?
- Intercept paste event in Javascript
- How to show a spinner while loading an image via JavaScript
- How do I serialize a DOM to XML text, using JavaScript, in a cross browser way?
- How do you set the document title in React?
- contentDocument for an iframe
- Can I change an HTML element’s type?
- “Cut and Paste” – moving nodes in the DOM with Javascript
- How to reference the caller object (“this”) using attachEvent
- Remove specific HTML tag with its content from javascript string
- Is it possible to programmatically catch all events on the page in the browser?
- how to compare two elements in jquery [duplicate]
- Is there any way to accelerate the mousemove event?
- How do I wrap a text selection from window.getSelection().getRangeAt(0) with an html tag?
- Inject CSS stylesheet as string using Javascript
- JavaScript: Is it better to use innerHTML or (lots of) createElement calls to add a complex div structure? [duplicate]
- Getting the text from a drop-down box
- Accessing a DOM object defined in an external SVG file
- How can I replace one class with another on all elements, using just the DOM?