Writing directly to the html-text

Discussion in 'JavaScript' started by TriKri, Jul 9, 2007.

  1. #1
    Hello! I have been looking at JavaScript for the last time and it really seems great! I have seen how you can change properties for elements, for example, changing the value of a text box to display text in it, but is there some way to write text between html-tags? For example, if a user click on a button a javascript should be run which creates a new table with one row and one cell, placing the table somewhere between the two body tags?
     
    TriKri, Jul 9, 2007 IP
  2. spiderman05

    spiderman05 Banned

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Of course it is possible. The best way to do it is to create a new div in your document, assign an id to it, say my_div, then you can set then content of that division using this statement:

    document.getElementsById("my_div").innerHTML = your_html_string;
     
    spiderman05, Jul 9, 2007 IP
  3. TriKri

    TriKri Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! :)
     
    TriKri, Jul 10, 2007 IP
  4. TriKri

    TriKri Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What about the root element, the element which contains the entire html code of the document? How can I access that element?

    For example, a page:

    <html>
      <head>
        <title>
          root element-test
        </title>
      </head>
      <body>
        Hello
      </body>
    </html>
    Code (markup):
    which element in the DOM will have an innerHTML-element with the value

    <html>
      <head>
        <title>
          root element-test
        </title>
      </head>
      <body>
        Hello
      </body>
    </html>
    Code (markup):
     
    TriKri, Jul 29, 2007 IP