Change event not fired on slider
Hi,
I'm new to jQueryMobile framework, while I was running some tests to better understand all the framework I've step into this piece of code (that I have written), that doesn't work and I can't understand why...
basically there are 2 pages, in each page there is a form with a slider that should react to the "change" event writing its value to a textbox. This works in the first page, but not in the second page although the code is the same...
- <!DOCTYPE html>
- <html>
- <head>
- <title>Page Title</title>
- <meta name="viewport" content="width=800, initial-scale=1">
- <link rel="stylesheet" href="jquery.mobile-1.4.0/jquery.mobile-1.4.0.min.css" />
- <script src="jquery-2.1.0/jquery-2.1.0.min.js"></script>
- <script src="jquery.mobile-1.4.0/jquery.mobile-1.4.0.min.js"></script>
-
- <script>
- $(document).ready(function() {
-
- $("#slider-1").change(function() {
- var sliderValue = $(this).val();
- $("#text-1").val(sliderValue);
- });
-
- $("#slider-2").change(function() {
- var sliderValue = $(this).val();
- $("#text-2").val(sliderValue);
- });
- });
- </script>
- </head>
- <body>
- <!-- /page1 -->
- <div data-role="page" id="page_1">
- <!-- /header -->
- <div data-role="header">
- <h1>Page 1</h1>
- </div>
- <!-- /content -->
- <div role="main" class="ui-content">
- <form id="form-1">
- <label for="slider-2">Slider-1:</label>
- <input type="range" name="slider-1" id="slider-1" data-highlight="true" min="0" max="100" value="50">
- <label for="text-1">Slider-1 value:</label>
- <input type="text" name="text-1" id="text-1" value="50">
- </form>
- <a href="#page_2" class="ui-btn">Page 2</a>
- </div>
- </div>
- <!-- /page2 -->
- <div data-role="page" id="page_2">
- <!-- /header -->
- <div data-role="header">
- <h1>Page 2</h1>
- </div>
- <!-- /content -->
- <div role="main" class="ui-content">
- <form id="form-2">
- <label for="slider-2">Slider-2:</label>
- <input type="range" name="slider-2" id="slider-2" data-highlight="true" min="0" max="100" value="50">
- <label for="text-2">Slider-2 value:</label>
- <input type="text" name="text-2" id="text-2" value="50">
- </form>
- <a href="#page_1" class="ui-btn">Page 1</a>
- </div>
-
- </div>
- </body>
- </html>
I can't understand why in the first page the change event is fired and not in the second page...
Samuele.