Enhancements not applied to slider inputs
Hi guys,
I'm dynamically generating a set of slider controls. These render as expected the first time they are built, in a $(document).ready() handler. However when I call the same build function as a result of the user clicking on a button, they are rendered without any jquery mobile enhancements. I've tried calling the .page() function on the containing page, calling the .input() function on the input and various other things to no avail.
Any ideas? Code below...
Thanks - Martin
- <!DOCTYPE html>
- <html>
- <head>
- <title>Sliders</title>
- <link rel="stylesheet" href="jquery.mobile-1.0a3.min.css" />
- <script type="text/javascript" src="jquery-1.5.min.js"></script>
- <script type="text/javascript">
- $(function(){
- $('#update').click(function(){
- createSliders()
- return false
- })
- createSliders()
- })
-
- function createSliders(){
- var sliderContainer = $('#sliderContainer')
- sliderContainer.children().remove()
- for (var i = 0; i < 3; i++) {
- var candidateName = 'Candidate ' + i
- var container = $('<div data-role="fieldcontain" class="ui-field-contain ui-body ui-br"></div>')
- container.append($('<label for="slider">' + candidateName + ' </label>'))
- var slider = $('<input type="range" name="slider" id="slider" value="0" min="-5" max="5"></input>')
- container.append(slider)
- sliderContainer.append(container)
- }
- $('#mypage').page()
- }
- </script>
- <script type="text/javascript" src="jquery.mobile-1.0a3.min.js"></script>
- </head>
- <body>
- <div data-role="page" id="mypage">
- <div data-role="header">
- <h1>Sliders</h1>
- </div>
- <div data-role="content">
- <a href="index.html" data-role="button" id='update'>Update</a>
- <div id='sliderContainer'/>
- </div>
- </div>
- </body>
- </html>