Jquery UI generated on the fly is not working -
i have jquery ui sliders different data-id. how possible detect selected , return sliders value in span next it?
i generate sliders , other elements dynamicaly:
<script> $(function() { $( "#slider" ).slider({ value:100, min: 0, max: 50000, step: 50, create: function () { $(this).slider( "option", "value", $(this).next().val() ); }, slide: function( event, ui ) { //get id of slider var id = $(this).data('id'); //select input box has same id slider within , set it's value current slider value. $("span[class*=" + id + "]").text(ui.value); //$("div[class*=" + id + "]").val(ui.value); } }); }); </script> <script> $(document).ready(function() { $("#adding").click(function() { var intid = $("#buildyourform div").length + 1; var fieldwrapper = $("<div class=\"fieldwrapper\" id=\"field" + intid + "\"/>"); var fname = $("<input type=\"text\" class=\"fieldname\" value=\"enter facebook fan page url\" />"); var ftype = $("<div id=\"slider\" datta-id=\"slider" + intid + "\" style='width:250px; float:left; margin-left:10px;'></div>").slider(); var flikes= $("<span class=\"slider" + intid + "\" style=\"width: 60px; height: 24px; float: left; margin-left: 13px; margin-top: 7px; border: 1px solid #999; color: rgb(243, 20, 145); text-align: center; font-family: serif;\" />"); var fcost = $("<div class=\"fieldname\" id=\"fcost" + intid + "\" style=\"width: 60px; height: 24px; float: left; margin-left: 6px; margin-top: 7px; border: 1px solid #999; color: rgb(243, 20, 145); text-align: center; font-family: serif;\" />"); var removebutton = $("<input type=\"button\" class=\"remove\" value=\"-\" />"); removebutton.click(function() { $(this).parent().remove(); }); fieldwrapper.append(fname); fieldwrapper.append(ftype); fieldwrapper.append(removebutton); fieldwrapper.append(flikes); fieldwrapper.append(fcost); $("#buildyourform").append(fieldwrapper); }); }); </script> , inside body: <fieldset id="buildyourform"> <legend>welcome! <span style="color:#f00; margin-left:13px;">my products</span></legend> </fieldset> <div id="adding"></div>
ok, doing make global variable store common properties of slider :
slider_options = { value:100, min: 0, max: 50000, step: 50, orientation: "horizontal", create: function( e, ui ) { //was throwing typeerror: closesthandle undefined previous code changed var bar=$(this).slider('value'); }, slide: function( event, ui ) { var id = $(this).data('id'); $("span[class*=" + id + "]").text(ui.value); }, };
and set can use in slider()
initialization code :
var ftype = $("<div id=\"slider\" data-id=\"slider" + intid + "\" style='width:250px; float:left; margin-left:10px;'></div>").slider(slider_options);
after can desired data-id
on slide
event of slider.
Comments
Post a Comment