views:

21

answers:

1

I have some objects, that keep created DOMObjects, like here:

function category(){
    var domBlock;
    this.block = function(){
        if (!domBlock){
           // Here dom-object constructor $('<div></div>'); etc
        }
        return domBlock; // jquery object,
               // but i test and native document.createElement
    }
 }

Then i clear category's area, and append old and new received(with Ajax) objects:

area.html('');
for(id in category_list){
     area.append( category_list[id].block() );
}

where category_list is list that contain category objects. Area is jQuery object.

In other browsers (except IE) i get area with all needed categories, but in IE i get only new received categories(that just create DomObject), other old objects that keeped old DomObject not show.

I know it possible make with innerHTML, but i wont keep DomObject, not text. Because DomObject keep many events. And it very hard for browser attach events for each DomObject after refresh area.

+2  A: 

Like comments suggest you can use .clone() for this, to eliminate your other problem, with events not copying, that's covered as well. .clone() takes a boolean parameter, telling it whether to copy data and events (this is as of jQuery 1.4, it was just events, not data, before then).

To use .clone(bool) and get a copy including event handlers, just do this:

return domBlock.clone(true);
Nick Craver
Thanks its work)
Kein