0

How to create a slider in JavaScript and HTML

const handleSliderRating = () => {
    let curVal = document.querySelector('.newpost-rating-slider').value;
    let sliderRatingEle = document.querySelector('.slider-rating-field');

    sliderRatingEle.textContent = curVal.toString() + "/5";
}


const slider = document.querySelector('.newpost-rating-slider');

slider.addEventListener('change', (event) => {
  handleSliderRating();
});
<input class="newpost-rating-slider" type="range" name="rangeInput" min="0" max="5"  />

<span class="slider-rating-field">0/5</span>
RUN
add comment
Suggest a different solution or add another example