How to create a link to the resource in the js?

The first time I write a private plugin for jQuery and here the question arose. Along with the future plugin are pictures to be referenced within the plugin. How to get and create a link to no matter where you run the plugin, the pictures were found?
For example, the folder structure is the following:
plugins
----myPlugin
--------img
------------image.png
--------myPlugin.js
--------example.html
www
----index.html
So, if the plugin contains string references "img/image.png" or "./img/image.png", in example.html everything works and in index.html no longer works. I would not want every plugin to pass the link.
July 2nd 19 at 13:12
2 answers
July 2nd 19 at 13:14
Solution
The correct way to use document.currentScript from src to carve the name of the script that there was only a folder, but this property (currentScript) is missing in IE. More cross-browser approach is to obtain an array of script elements and take the last. Here the drawback is that your script will be the last in the array only if it is connected to html. Any asynchronous loading does not guarantee order.
Know about these ways and when I stopped their use the limitations. Was wondering if there's a universal way, which I don't know yet. - euna.K commented on July 2nd 19 at 13:17
: Can use all options together. If there is a currentScript something. No - check the document.the readyState. If the DOM is even loaded, we take the last script tag. If already booted take a string given by the user if not passed - throw the error. Unfortunately, based on my knowledge, this is the best option. - Cruz commented on July 2nd 19 at 13:20
: doing so now Thank you. - euna.K commented on July 2nd 19 at 13:23
July 2nd 19 at 13:16
In this case the right to use more CSS to the plugin and specify the images relative to the stylesheet.
In my case, if I understand correctly, using css will not work, because I need this link to transfer to the api yandex map (link to the icon file that will be placed on the map) - euna.K commented on July 2nd 19 at 13:19
: well then, let users to specify when initializing the plugin the path setting to the folder with the files. - Cruz commented on July 2nd 19 at 13:22
: this possibility of course, I gave, but still wish the user had the ability to leave a standard picture icons are just not setting this option. - euna.K commented on July 2nd 19 at 13:25

Find more questions by tags JavaScriptjQuery