Last active
August 29, 2015 14:01
-
-
Save SeriousM/63a9834c9ca44082814b to your computer and use it in GitHub Desktop.
get executing script tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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