I`m trying to create flip toggle from code.
var favFlip = '<label for="favourFlip">To fav:</label>'+
'<select id="favourFlip" data-role="slider">'+
'<option value="off">Off</option>'+
'<option value="on">On</option>'+
'</select>';
$('.ui-content').append(favFlip);
var flip = $('#favourFlip');
flip.slider('refresh');
This code work in pagebeforeshow handler and throw error: Uncaught cannot call methods on slider prior to initialization; attempted to call method 'refresh'. How fix it?
You may want to try running it in
pageshow, then the DOM is certainly loaded and your container for$('#favourFlip')will be initialized.Edit: Try:
.slider(). You do this because you are creating a slider object and not updating an already existing one.Example: http://jsfiddle.net/Calavoow/724yH/3/