Get all children and their childeren - not innerHTML

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2008
Posts: 2
Reputation: ehsun7b is an unknown quantity at this point 
Solved Threads: 0
ehsun7b ehsun7b is offline Offline
Newbie Poster

Get all children and their childeren - not innerHTML

 
0
  #1
Nov 5th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 24
Reputation: sasankasekhar is an unknown quantity at this point 
Solved Threads: 3
sasankasekhar's Avatar
sasankasekhar sasankasekhar is offline Offline
Newbie Poster

Re: Get all children and their childeren - not innerHTML

 
0
  #2
Nov 11th, 2008
Originally Posted by ehsun7b View 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?

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 ...
IF SOMEONE FEELS THAT THEY HAD NEVER MADE A MISTAKE IN THEIR LIFE, THEN  IT MEANS THEY HAD NEVER TRIED A NEW THING IN THEIR LIFE
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: ehsun7b is an unknown quantity at this point 
Solved Threads: 0
ehsun7b ehsun7b is offline Offline
Newbie Poster

Re: Get all children and their childeren - not innerHTML

 
0
  #3
Nov 11th, 2008
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC