As your Ajax result is a TD, innerHTML wont work if you don't create
whole TABLE with TBODY. You should do this:

var old = $('thisisatd');

var tr = TR(null);
var tbl = TABLE(null, TBODY(null, tr));

tr.innerHTML = '<td id="thisisatd" colspan="3">A new text</td>';

swapDOM(old, tr.firstChild);

For your information, I'm implementing a jQuery style helper module
(see previous post) that will easy such tasks, for example:

MochiKit.Query('#thisisatd').replaceWith('<td id="thisisatd"
colspan="3">A new text</td>');

The MochiKit.Query will take care of creating valid DOM from the given
row html text and also executes JavaScript within the text if any.
Though almost finished, the module is still not made public. I'm
reviewing some of the code and will release the code within a week or
so...

Regards
..
Amit Mendapara


On Sep 8, 4:43 pm, 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?
>
> Pseudo example:
>
> <html>
> <table>
> <tr><td id="thisisatd" colspan="2">A text</td></tr>
> </table>
> </html>
>
> From the Ajax call I get the string back "<td id="thisisatd"
> colspan="3">A new text</td></tr>".
> How can I replace the td with this new string?
>
> My current function to do this looks like this:
>
>     var doReplace = function (req) {
>         for (var e in req.changes) {
>             var element = document.getElementById(e)
>             if (element) {
>                 element.outerHTML = req.changes[e];  // <- Does not work in 
> Firefox
>            }
>             else {
>                 alert("element not found:" + e);
>             }
>         }
>     }
--~--~---------~--~----~------------~-------~--~----~
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