Save Jquery Object without losing its binding
- by Ahmad Satiri
Hi
I have object created using jquery where each object has it's own binding.
function closeButton(oAny){
var div = create_div();
$(div).attr("id","btn_"+$(oAny).attr("id"));
var my_parent = this;
$(div).html("<img src='"+ my_parent._base_url +"/assets/images/close.gif'>");
$(div).click(function(){
alert("do some action here");
});
return div;
}
var MyObject = WindowObject();
var btn = closeButton(MyObject);
$(myobject).append(btn);
$("body").append(myobject); //at this point button will work as i expected
//save to array for future use
ObjectCollections[0] = myobject;
//remove
$(myobject).remove();
$(body).append(ObjectCollections[0]); // at this point button will not work
For the first time i can show my object and close button is working as i expected. But if i save myobject to any variable for future use. It will loose its binding. Anybody ever try to do this ? Is there any work around ? or It is definitely a bad idea ? .And thanks for answering my question.