Save Jquery Object without losing its binding

Posted by Ahmad Satiri on Stack Overflow See other posts from Stack Overflow or by Ahmad Satiri
Published on 2010-04-17T03:13:02Z Indexed on 2010/04/17 3:23 UTC
Read the original article Hit count: 280

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about object