innerHTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alejandro Narancio

    innerHTML

    Hi for everyone. First of all i'm trying to explain waht i want to do.
    I need to insert some code (for example the beggining of a table)
    before the code inside of a div, and some other code (for exaple the
    end of a table) after the code inside of a div. Here is an example:

    Actual code:

    <body>
    <div id="idDIV">
    <table>
    <tr>
    <td>Some text</td>
    </tr>
    </table>
    </div>
    </body>


    I want to make the code above like this:


    <body>
    <div id="idDIV">
    <table>
    <tr>
    <td>
    <table>
    <tr>
    <td>Some text</td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>
    </body>

    I'm trying to do this with this code:
    var code = '<table><tr><td >'+document.all .idDIV.innerHTM L+'</td></tr></table>';
    document.all.id DIV.innerHTML = "";
    document.all.id DIV.innerHTML = code;

    This code work if inside the Div there isn't a table, if inside the
    div exists a table an error ocur: "Untermiate d string"

    Anybody know hoy can i fix this?

    Thanks,

    Alejandro
  • Thomas 'PointedEars' Lahn

    #2
    Re: innerHTML

    Alejandro Narancio wrote:[color=blue]
    > I'm trying to do this with this code:
    > var code = '<table><tr><td >'+document.all .idDIV.innerHTM L+'</td></tr></table>';
    > document.all.id DIV.innerHTML = "";
    > document.all.id DIV.innerHTML = code;
    >
    > This code work if inside the Div there isn't a table, if inside the
    > div exists a table an error ocur: "Untermiate d string"
    > Anybody know hoy can i fix this?[/color]

    Try to replace "</" with "<\/". ETAGOs must not occur within CDATA,
    otherwise the element is considered closed and the element's content
    is incomplete code (which would explain the error message).

    BTW, "document.a ll" is (currently) IE-only (some UAs like Opera emulate
    parts of its object model, though) and both the former and "innerHTML"
    are proprietary. Use document.getEle mentById("idDIV ").textCont ent
    (DOM Level 3) or its DOM Level 2+ node manipulation methods instead.


    PointedEars

    Comment

    Working...