Use a variable defined in another function in jquery [duplicate]

56
December 26, 2018, at 06:50 AM

This question already has an answer here:

  • How do I return the response from an asynchronous call? 33 answers

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

Answer 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"/>

READ ALSO
Jquery tablesorter plugin does not work in Django template

Jquery tablesorter plugin does not work in Django template

Trying to use the table sorting JQuery plugin in the Django templateTried different sources for jquery and tablesorter files

11
How do i compare dates from mongodb in nodeJS [on hold]

How do i compare dates from mongodb in nodeJS [on hold]

I want to compare date that i fetch from mongodb and the one i provide while running the program(in nodejs)

60
While loop not breaking when condition met for validating input entry

While loop not breaking when condition met for validating input entry

The false condition for while loop is met and even prints as suchYet, the while loop continues

37
Is It possible to make a string reverse using css without using &ldquo;rtl&rdquo; ?

Is It possible to make a string reverse using css without using “rtl” ?

Is It possible to make a string reverse using css without using "rtl" ? Example:- "Hello World" to "World Hello"

36