Skip to content

Instantly share code, notes, and snippets.

@ryansukale
Created April 29, 2011 06:16
Show Gist options
  • Save ryansukale/947930 to your computer and use it in GitHub Desktop.
Save ryansukale/947930 to your computer and use it in GitHub Desktop.
Find the current directory of your script from within your javascript using jQuery
/*This code returns the path of the currently executing javascript file. This path can then be used to find relative paths to other files like the css files and images that are specific to this js file.
Should come in handy when making jQuery plugins if your script file makes used of script specific css. You can simply use string manipulation to create the relative path for your css.
Recommended use at the top of your plugin.
*/
var jsFilePath = $("head").find("script:last").attr('src');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment