javascript - dynamic slider value not working (ui.value) -


i'm trying print value of dynamic sliders value it's not added inputs:

$(document).ready(function () {     var n = 10;     var initval = 1;      (var id = 1; id <= n; id++) {          var $newresult = $('<input/>', {             type: 'text',             id: 'result-' + id,             class: 'slidertext',             value: initval         });          var $newslider = $("<div/>", {             id: 'slider-' + id,             class: 'ui-slider'         }).slider({             range: 'min',             min: initval,             max: n,             value: initval,             step: 1,             slide: function(event, ui) {                 $newresult.val(ui.value);  // neither works $( '#result-' + id )             }         });         var $container = $("<div/>", {             id: 'slidercontainer-' + id         }).append($newresult).append($newslider);          $("#showsldr").append($container);     } }); 

it's seems there don't see, maybe :p

http://jsfiddle.net/fjs1plv2/

since you're reusing $newresult variable need retain each reference in closure:

  slide: (function($input) {      return function(event, ui) {          $input.val(ui.value);      };   })($newresult) 

http://jsfiddle.net/fjs1plv2/2/


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -