PDA

View Full Version : Replacing a div



brookd
17 Mar 2009, 1:48 PM
I know this should be easy. I have a div that I want to replace with another div. They both have the same ID. I want to replace the existing element with an HTML fragment.

I have tried just about everything I can think of. The below attempts only update the inner element and leave the outer div (and I end up with two divs with the same ID)



Ext.get('myElId').update(htmlfragment)




Ext.get('myElId').replaceWith(htmlfragment)


So I tried to render the element first so I could use the replace() method:



Ext.get('myElId').replace(
Ext.getBody().insertHtml('beforeEnd',htmlfragment,true)
)


This doesn't work either, I assume because the ID's are the same. Now, I guess I could append the element to the body and then change the ids (but there are 3 nested divs with id's aswell) but this seems like it should be simpler.

Anybody?

17 Mar 2009, 2:13 PM
Ext.fly('test').replaceWith({tag:'div', html : 'blah'});

brookd
21 Mar 2009, 12:32 PM
Thank you for your reply! I missed it until just now. Will this work if I have nested divs? I don't think so? Can I do



Ext.fly('test').replaceWith({tag:'div', html : '<div><div></div></div>'});


If not, I don't know what to do because the contents of the replace string is dynamic, so I can not build out the domConfig object to include the children array because I do not know what it will contain.

There has to be an easy way to do this no?

shibubh
21 Mar 2009, 9:13 PM
Thank you for your reply! I missed it until just now. Will this work if I have nested divs? I don't think so? Can I do



Ext.fly('test').replaceWith({tag:'div', html : '<div><div></div></div>'});




you can do that.

watrboy00
21 Mar 2009, 9:55 PM
Could also do...

Ext.fly('test').replaceWith({
cn: [{
cn: [{
tag: 'div'
}],
tag: 'div'
}],
tag:'div'
});