I needed a range slider and I couldn’t get it to work, so I pasted whole example code into html file and it still doesn’t work. Any help of what I could do to fix it? With this code copy pasted into html I just get a blank website. .
Advertisement
Answer
I hope it helps you my friend:
JavaScript
x
13
13
1
$( function() {
2
$( "#slider-range" ).slider({
3
range: true,
4
min: 0,
5
max: 500,
6
values: [ 75, 300 ],
7
slide: function( event, ui ) {
8
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
9
}
10
});
11
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
12
" - $" + $( "#slider-range" ).slider( "values", 1 ) );
13
} );
JavaScript
1
9
1
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
2
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
3
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
4
<p>
5
<label for="amount">Price range:</label>
6
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
7
</p>
8
9
<div id="slider-range"></div>
complete html is here:
JavaScript
1
37
37
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset='utf-8'>
5
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
6
<title>Page Title</title>
7
<meta name='viewport' content='width=device-width, initial-scale=1'>
8
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
9
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
10
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
11
</head>
12
<body>
13
14
<p>
15
<label for="amount">Price range:</label>
16
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
17
</p>
18
19
<div id="slider-range"></div>
20
</body>
21
<script>
22
$( function() {
23
$( "#slider-range" ).slider({
24
range: true,
25
min: 0,
26
max: 500,
27
values: [ 75, 300 ],
28
slide: function( event, ui ) {
29
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
30
}
31
});
32
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
33
" - $" + $( "#slider-range" ).slider( "values", 1 ) );
34
} );
35
</script>
36
</html>
37