Don’t use innerHTML, but use Prototype’s Element.update method!

Note to self: When using prototype don’t use the innerHTML property.

Internet Explorer has got a (in my opinion) broken implementation for certain elements.
It is not possible to change the innerHTML content of the TR and SELECT elements.

Fortunally Prototype has fixed these problems in the Element.update method!

$(“tr_id”).update( “<td>Test</td>” );

5 Comments so far

  1. abi on March 7th, 2008

    brilliant. i’ve only recently begun using the JS prototype framework and was looking for a function to replace innerHTML. i must have overlooked this in the API documentation.

    thank you so much.

    xx

  2. Rene on March 22nd, 2009

    Perfect. Also fixes the problem of the disappearing SCRIPT tags in IE7 when dynamically adding javascritp to the DOM.

    elm.innerHTML(’…’)
    Some times (not always) the script node disappears

    elm.update(’…’)
    Works. The script still needs to be run using eval later tthough

  3. dan on July 8th, 2009

    What if I just want to read the inner html and use it elsewhere? Such as to parse my ajax response 17 to retrieve the 17 to use elsewhere.

  4. dan on July 8th, 2009

    trying that again:
    What if I just want to read the inner html and use it elsewhere? Such as to parse my ajax response
    <div id=”tool_body”>17</div> to retrieve the 17 to use elsewhere.

  5. admin on July 8th, 2009

    Reading is no problem, the problem is writing to innerHTML.

Leave a reply