title: JavaScript to output html range slider values for multiple sliders
body: <p>I want to create two range sliders in html and display their current value with a JS script below each slider. But in my code both sliders will output their value to the same "value output" (the one for the slider with <code>id="myRange2"</code>). Why does this happen and how can I fix this?</p>
  
  <p><a href="https://i.stack.imgur.com/X2NMg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X2NMg.png" alt="enter image description here"></a></p>
  
  <p>I tried to make the <code>slider</code> and <code>output</code> variables unique for each slider script, but that does not solve my problem.</p>
  
  <p><a href="https://stackoverflow.com/questions/26564274/html-javascript-range-slider">This</a> issue is similar, but I am not so familiar with JS and I think my solution might be more simple.</p>
  
  <p>This is my <code>.html</code> code with the JS scripts at the end:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div class="slidecontainer"&gt;
    &lt;input type="range" min="1" max="100" value="50" class="slider" id="myRange"&gt;
    &lt;p&gt;Value: &lt;span id="demo"&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;div class="slidecontainer"&gt;
    &lt;input type="range" min="1" max="100" value="50" class="slider" id="myRange2"&gt;
    &lt;p&gt;Value: &lt;span id="demo2"&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  var slider = document.getElementById("myRange");
  var output = document.getElementById("demo");
  output.innerHTML = slider.value;
  
  slider.oninput = function() {
    output.innerHTML = this.value;
  }
  &lt;/script&gt;
  
  &lt;script&gt;
  var slider = document.getElementById("myRange2");
  var output = document.getElementById("demo2");
  output.innerHTML = slider.value;
  
  slider.oninput = function() {
    output.innerHTML = this.value;
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>