DOM get Element Content

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bilibytes
    New Member
    • Jun 2008
    • 128

    DOM get Element Content

    Hi,

    I am trying to get the content of an element and reuse it elsewhere in the script

    lets say i have:

    Code:
    <div id="content">
       <ul name="subcontainer">
          <li name="header"><h3>Title</h3><h4>Text here...</h4></li>
          <li name="image"><img class="foto" src="3396/2.jpg"/></li>
          <li name="listcontent">Text Here...</li>
          <ol name="language">
             <li><img src="/images/es.gif" alt="es"/></li>
          </ol>
       </ul>
       <ul name="subcontainer">
          <li name="header"><h3>Title</h3><h4>Text here...</h4></li>
          <li name="image"><img class="foto" src="3396/2.jpg"/></li>
          <li name="listcontent">Text Here...</li>
          <ol name="language">
             <li><img src="/images/es.gif" alt="es"/></li>
          </ol>
       </ul>
    <div>
    Ok so what i want to do, is tu reuse the code contained into the Element named "subcontainer".
    The point is that there are multiple of those. I am able to target the one that i need (in fact, it is the one that the user clicks on).
    Once i have the <ul> element under a variable (named: selectedNode), i would like to be able to somwhere say:

    [HTML]document.getEle mentById("conte nt").innerHTML. selectedNode;[/HTML]

    The problem is that this will return an object, and will not print the content of the node, as i want it to do.

    My question is,
    Is there a way to access the selectedNode's content, assuming that the content is compound by multiple nodes and different levels of nodes?

    thankyou very much

    bili
  • zaphod42
    New Member
    • Oct 2008
    • 55

    #2
    Code:
    document.getElementById("content").innerHTML.selectedNode;
    should be

    Code:
    document.getElementById("content").innerHTML = selectedNode;

    Comment

    • bilibytes
      New Member
      • Jun 2008
      • 128

      #3
      Originally posted by zaphod42
      Code:
      document.getElementById("content").innerHTML.selectedNode;
      should be

      Code:
      document.getElementById("content").innerHTML = selectedNode;
      Yes you are right, and it is this way in my script, i miscopied this bunch of code, but this is not the problem,
      with the code you wrote, it will return[ListTypeObject] and what I need is to reuse the list with all its contents in another part of the script.

      I don't know if i have to parse the whole list creating variables with each node or if there is a shortcut that would allow me to take all the list content and do:

      Code:
      document.getElementById("content").innerHTML = selectedNode;
      [/QUOTE]

      Thanks any way

      Comment

      • bilibytes
        New Member
        • Jun 2008
        • 128

        #4
        it was appendChild!
        Code:
        document.getElementById("content").appendChild(selectedNode);
        [/QUOTE]

        Comment

        Working...