Skip to content

Instantly share code, notes, and snippets.

@SeriousM
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeriousM/63a9834c9ca44082814b to your computer and use it in GitHub Desktop.
Save SeriousM/63a9834c9ca44082814b to your computer and use it in GitHub Desktop.
get executing script tag
<script>
/* another block */
</script>
<script data-test-value="xyz">
//http://stackoverflow.com/a/2954896
// this works because the processing of script blocks is serial
// and others does not exist in that moment of execution.
// works with script-references
// does NOT work with async's
var toArray =Array.prototype.slice;
var scripts = toArray.call(document.scripts);
toArray.call(scripts[scripts.length - 1].attributes)
.forEach(function(es){
alert(es.nodeName + ': ' + es.nodeValue); // -> "data-test-value: xyz"
});
</script>
<script>
/* another block */
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment