title: WordPress - Plugin - enqueue image files from WP plugin directory in a JS-file
body: <p>I'm new with creating plugins for WP and I'm still learning. I have two questions concerning the same issue:</p>
  
  <p>1: 
  First I included the js-file in my plugins <strong>php-file</strong>:</p>
  
  <pre><code>function theme_name_scripts() {
  wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js');
  }
  
  add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
  </code></pre>
  
  <p>It works but what I want to do is to locate it from my plugins url (wordpress/wp-content/plugins/example), not from my template directory. How do I do this?</p>
  
  <p>2:
  In my <strong>js-file</strong>, I need to include some image files from the plugin base url (wordpress/wp-content/plugins/example/pix). This script worked when not used as a plugin:</p>
  
  <pre><code>window.onload=function()
  {
  
  /* Example */
  
  bp='/pix/', // base url of my images
  
  imgnum=4, // number of images
  thumb1=document.getElementById('thumb1'), // id of changing image
  combobox1=document.getElementById('selection1'); // id of combobox.
  
  combobox1.onchange=function()
  {
  thumb1.src=bp+'imagefile'+this.value+'.png';
  }
  </code></pre>
  
  <p>I understand that <code>bp='/pix/',</code> is wrong. But what is correct? I want to load the images from a folder in <code>template_directory</code>. How do I do this? I have read through these two threads but I cant seem to figure it out:</p>
  
  <p><a href="https://stackoverflow.com/questions/12426710/wordpress-how-can-i-pick-plugins-directory-in-my-javascript-file">Wordpress: How can I pick plugins directory in my javascript file?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9631910/write-php-inside-javascript-alert">write php inside javascript alert</a></p>