Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active December 23, 2015 23:59
Show Gist options
  • Save cowboy/6713986 to your computer and use it in GitHub Desktop.
Save cowboy/6713986 to your computer and use it in GitHub Desktop.
javascript: get last script by src filename
// For Remy
function getLastScriptBySrc(filename) {
var scripts = document.scripts;
var i = scripts.length - 1;
while (i--) {
if (scripts[i].src.slice(-filename.length) === filename) {
return scripts[i];
}
}
return null;
}
var script = getLastScriptBySrc("/1.js");
@cowboy
Copy link
Author

cowboy commented Sep 26, 2013

note: untested in anything but Chrome latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment