943,878 Members | Top Members by Rank

Ad:
Nov 5th, 2008
0

Get all children and their childeren - not innerHTML

Expand Post »
I need to get all children of a DIV and their children too. I mean I need to get the HTML text of a DIV but I don't like to use innerHTML since it does not support the values of inputs in many browsers. How can I do that?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ehsun7b is offline Offline
7 posts
since Nov 2008
Nov 11th, 2008
0

Re: Get all children and their childeren - not innerHTML

Click to Expand / Collapse  Quote originally posted by ehsun7b ...
I need to get all children of a DIV and their children too. I mean I need to get the HTML text of a DIV but I don't like to use innerHTML since it does not support the values of inputs in many browsers. How can I do that?

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="JavaScript">
  2. function test(){
  3. var listOfChildNodes = document.getElementById('IDofTheDiv').childNodes;
  4. var numberOfChildNodes = listOfChildNodes.length;
  5. var str="";
  6. for(i=0;i<numberOfChildNodes;i++){
  7. str += listOfChildNodes[i].tagName+"\n";// this is the way you access childNodes ... tagName is just for example purpose.
  8. }
  9. alert(str);
  10. }
  11. </script>
  12. <div id= "IDofTheDiv">
  13. <span></span>
  14. <p></p>
  15. <a></a>
  16. </div>
  17. <a href="javascript:test()">Click Here</a>

This is NOT what you exactly want .... but hope this would be of your help.

Regards ...
Reputation Points: 10
Solved Threads: 3
Newbie Poster
sasankasekhar is offline Offline
24 posts
since Jan 2007
Nov 11th, 2008
0

Re: Get all children and their childeren - not innerHTML

Thanks
And how should I do the reverse action? I mean if I have a string which contains HTML tags, how can I add it to a DIV content element by element and in the same precedence?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ehsun7b is offline Offline
7 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: using javascript to alter css of iframe div
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: create and append div to body tag





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC