Sunday, 18 August 2013

How to bind a dynamically created object to the document ready event?

How to bind a dynamically created object to the document ready event?

I have a function that dynamically creates a slider element using the
following code:
function NewDiv(){
for (var count=0; count < parseFloat(sessvars.storey_count); count++)
{
var string="<br><div id='my-slider"+count+"'
class='dragdealer'><div class='red-bar handle'><span
id='drag-button"+count+"'>drag me</span></div></div>";
$("body").append(string);
var slider_id ="my-slider"+count;
var drag_button_id = "drag-button"+count;
//OBJECT GETS CREATED BELOW
new Dragdealer(slider_id,{horizontal:
true,x:Math.random(),animationCallback: function(x, y){
document.getElementById(drag_button_id).innerHTML =
x.toFixed(2);
}
});
}
}
However, the animationCallback function which is invoked everytime the
slider is moved has to be embedded within a function listener, and I have
to somehow bind it to maybe the ready event. Is this the best way to make
the slider update when its value changes? And if so, how do I go about
doing this?

No comments:

Post a Comment