By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,985 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

DOM get Element Content

bilibytes
100+
P: 128
Hi,

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

lets say i have:

Expand|Select|Wrap|Line Numbers
  1. <div id="content">
  2.    <ul name="subcontainer">
  3.       <li name="header"><h3>Title</h3><h4>Text here...</h4></li>
  4.       <li name="image"><img class="foto" src="3396/2.jpg"/></li>
  5.       <li name="listcontent">Text Here...</li>
  6.       <ol name="language">
  7.          <li><img src="/images/es.gif" alt="es"/></li>
  8.       </ol>
  9.    </ul>
  10.    <ul name="subcontainer">
  11.       <li name="header"><h3>Title</h3><h4>Text here...</h4></li>
  12.       <li name="image"><img class="foto" src="3396/2.jpg"/></li>
  13.       <li name="listcontent">Text Here...</li>
  14.       <ol name="language">
  15.          <li><img src="/images/es.gif" alt="es"/></li>
  16.       </ol>
  17.    </ul>
  18. <div>
  19.  
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.getElementById("content").innerHTML.selec tedNode;[/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
Oct 24 '08 #1
Share this Question
Share on Google+
3 Replies


P: 55
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content").innerHTML.selectedNode;
should be

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content").innerHTML = selectedNode;
Oct 24 '08 #2

bilibytes
100+
P: 128
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content").innerHTML.selectedNode;
should be

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content").innerHTML = selectedNode;
[/quote]

Thanks any way
Oct 24 '08 #3

bilibytes
100+
P: 128
it was appendChild!
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content").appendChild(selectedNode);
[/quote]
Oct 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.