On Mon, Sep 8, 2008 at 14:52, Arnar Birgisson <[EMAIL PROTECTED]> wrote:
> On Mon, Sep 8, 2008 at 13:43, gregor <[EMAIL PROTECTED]> wrote:
>> I would like to change a DOM Object with a turbogears ajax call.
>> At the moment the ajax call returns a string with the html of the node
>> that should be replaced. How can I swap the existing DOM Object with
>> the new one I got from the ajax callback?
>>
>> InnerHTML replaces the inner part of the element, but I want to
>> replace the whole thing. OuterHtml seems to what I need but it does
>> not work in Firefox. swapDOM takes two DOM-Objects, but I've only got
>> a string for the replacement. How can I convert a string to a DOM
>> object?
>
> First of all, not that in general a string can represent a HTML
> fragment containing more than one element. Consider:
>
> "<td>number1</td><td>number2</td>"
>
> My point is that you cannot take any string and convert it to just one
> DOM element. However, say your strings always contain one complete
> element, or that you just want to pick out the first one, you can
> create a temporary element (not injected in the document) to use
> innerHTML on, and the use swapDOM to inject the first child. I.e.
> (note, this is untested code written directly in the email):
>
> var str = "<td>something from an ajax call</td>";
> var container = DIV();
> container.innerHTML = str;
> swapDOM("id-of-element-to-remove", container.firstChild);

Here's a quick test:
http://www.hvergi.net/arnar/public/test/load.html

cheers,
Arnar

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to