user1574598
user1574598

Reputation: 3881

Retrieving a value from a HTML5 slider with JQuery

I'm having trouble retrieving a value from a HTML5 slider using JQuery. Here is my code:

JQuery:

  // Retrieve the value from slider one
  $("#submit").on("click", function(evt) {
      var sliderValue = $('#slider01').attr('value');
      alert("The value of slider 1 is: " + sliderValue);
  });

HTML:

  <input id="slider01" type="range" name="slider1" min="0" max="10" value="5">
  <span id="value">0</span>

It keeps telling me in the alert box that the value is 5 no matter where I move the slider.

Upvotes: 1

Views: 113

Answers (1)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

change this:

var sliderValue = $('#slider01').attr('value');

to this:

var sliderValue = $('#slider01').val();

Upvotes: 2

Related Questions