Example:
<script>
// I want to have the dom element of the script tag that is holding the code that goes here
</script>
If I do:
<script>
alert(this)
</script>
this is the window.
I want to access the script tag itself.
Example:
<script>
// I want to have the dom element of the script tag that is holding the code that goes here
</script>
If I do:
<script>
alert(this)
</script>
this is the window.
I want to access the script tag itself.
This should find the <script> elements you have in your page.
var scripts = document.getElementsByTagName("script");
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];
// Now you can do stuff with script
}
If you want the one the code is in I think you can do this:
var scripts = document.getElementsByTagName("script");
var script = scripts[scripts.length - 1];
Just curious: what do you want to do with it once you've got it?