开发者

Cant append "used" DOMObject in IE

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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜