This works fine but when I have two sliders, the javasctript causes problems because both have the same id “range”. How can I modify the js to allow two sliders to be on the same page? Thanks
<li>
<label for="budget">Budget*</label>
<input type="range" min="1000" max="10000" value="2000" step="1000" onchange="showValue(this.value)">
<span id="range">$2000</span>
<script>
function showValue(newValue)
{
document.getElementById("range").innerHTML=newValue;
}
</script>
</li>
The solution is to use classes instead of ids.
Also, do not mix vanilla JavaScript with jQuery in this way. If you are using jQuery use it anywhere you will
interact withmanipulate the DOM.1. HTML:
2. jQuery:
3. Demo