title: use one function to different elements javascript
body: <p>I'm new in JavaScript and I'm tring to find out how I can use the same function to different elements in JavaScript.</p>
  
  <p>I.e. how to set the id value for <code>document.getElementById</code> in the function. I do not know why my code does't work.</p>
  
  <p>JavaScript</p>
  
  <pre><code>function onhover(imgx)
  {
      var x = imgx;
      document.getElementById('x').style.opacity=0.5;
  }
  </code></pre>
  
  <p>HTML  </p>
  
  <pre><code>&lt;img id="img1" src="img1.jpg" onmouseout="onhover('img1')"&gt;
  &lt;img id="img2" src="img2.jpg" onmouseout="onhover('img2')"&gt;
  </code></pre>