0

I have a Range Slider I want to put it in variables with each change and then use it. In my code this is undefined

My html code is

<input id="length" class="border-0" type="range" value="10" min="max="100"/>

and my jquery code is

$('#length').change(function () {
    length = $(this).val();
    console.log($(this).val())
});
console.log(length)

but it return undefiend

Arman Bagheri
  • 608
  • 7
  • 19

1 Answers1

1

Including JQuery library into the script will make it work just fine.

var length;
$('#length').change(function () {
    length = $(this).val();
    console.log($(this).val())
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="length" class="border-0" type="range" value="10" min="max="100"/>
holydragon
  • 6,158
  • 6
  • 39
  • 62