Jack McKalling Posted October 4, 2005 Share Posted October 4, 2005 (edited) How exactly can they be used?childNodes[#], childNode, parentNode, parentNodes[#] (I don't know which exists)It hasn't been explained at the tutorials Much need of them though Edited October 4, 2005 by Dan The Prof Link to comment Share on other sites More sharing options...
Webworldx Posted October 7, 2005 Share Posted October 7, 2005 <div id="testDiv"><span id="internalspan"><b>Text</b></span></div><script>var divLayer = document.getElementById('testDiv');alert(divLayer.childNodes.length); //returns 1 (the SPAN)alert(divLayer.childNodes[0].childNodes.length); //returns 1 (the <B> tag)alert(divLayer.childNodes[0].childNodes[0].innerHTML); //returns Textalert(divLayer.childNodes[0].innerHTML); //returns <b>Text</b>alert(divLayer.childNodes[0].childNodes[0].parentNode.parentNode.innerHTML); //returns <span id... ../span></script> Link to comment Share on other sites More sharing options...
Jack McKalling Posted October 7, 2005 Author Share Posted October 7, 2005 Cool, but what if the innerHTML of some element is not just another element, but also text? Can I use .childNodes then too?Can't Refsness add some of these things to the DOM Tut? Link to comment Share on other sites More sharing options...
Webworldx Posted October 7, 2005 Share Posted October 7, 2005 alert(divLayer.childNodes[0].childNodes[0].innerHTML); //returns Text^^ Does text. Link to comment Share on other sites More sharing options...
Jack McKalling Posted October 7, 2005 Author Share Posted October 7, 2005 You don't understand. If I had something like this: <div id="border"><span id="selection">Hello <b>World!</b></span></div>Now the span has both text and an element directly inside. This way,document.getElementById("border").childNodes[0].childNodes[0].innerHTMLwon't work anymore because the second childNodes[0] is not the first content, the text "Hello " is. Link to comment Share on other sites More sharing options...
Webworldx Posted October 8, 2005 Share Posted October 8, 2005 What you're asking doesn't make sense. Use:document.getElementById("border").childNodes[0].innerHTML if you just wanted the Hello <b>World!</b>Or were you looking for a way to just display text with no tags? That isn't what childNodes is specifically for, you could just strip the tags out of innerHTML otherwise.Explain it a bit more clearly what you actually want. Link to comment Share on other sites More sharing options...
Jack McKalling Posted October 8, 2005 Author Share Posted October 8, 2005 What I actually want is advanced explaining at the tutorial :)You might explain it too, then i'll try to make it clear:I tried to use the childNodes thing. Tried, because it would not work :)If there is an parent element with both text and embeded child elements, and the text comes before the embeded element, the_parent_element.childNodes[0]Would not work because it is followed by text instead of being the first content of parent_elementI hope now I am clear Link to comment Share on other sites More sharing options...
Webworldx Posted October 8, 2005 Share Posted October 8, 2005 Could you put up an example of what you're attempting to do?Say you have something like this: <div id="outerDiv">Text <span>in here</span> out of here</div><script type="text/javascript"> var divLayer = document.getElementById('outerDiv') alert(outerDiv.childNodes[0].data); //Text alert(outerDiv.childNodes[1].innerHTML); //in here alert(outerDiv.childNodes[2].data); //out of here</script> Link to comment Share on other sites More sharing options...
Jack McKalling Posted October 9, 2005 Author Share Posted October 9, 2005 (edited) .data? :DThat is just another new thing for me...Could someone please phonecall Refsness so they add all this to the tutorial? :)My head burns with al those newbees and I am getting burned up by questions about them all (It is that I do like to get answered at the forums, but more like to read the answer at the tut so I and many other people can learn it advancedly )I can't find anything about these things at the Html DOM tut, why not?Why are childNodes[] not a W3C standard? Edited October 9, 2005 by Dan The Prof Link to comment Share on other sites More sharing options...
Webworldx Posted October 9, 2005 Share Posted October 9, 2005 As I remember, childNodes is DOM core Level 1 specs... How else would you walk the DOM tree without .all or .getElementsByTagName('*').. ?? Link to comment Share on other sites More sharing options...
Jack McKalling Posted October 10, 2005 Author Share Posted October 10, 2005 Actually, I try to avoid using .getElementsByTagName() and .all while they both are not w3c standard, .all because div layers are even only supported by netscape or some.Ahwell, I don't care about them being not standard. If I have to use them, I do, else, I'll think of something more usable. Link to comment Share on other sites More sharing options...
Webworldx Posted October 10, 2005 Share Posted October 10, 2005 .getElementsByTagName() is w3c standard... again.. Level 1 DOM ( http://www.w3.org/TR/1998/REC-DOM-Level-1-...l-one-core.html ). Where are you getting this information from? Link to comment Share on other sites More sharing options...
Jack McKalling Posted June 6, 2006 Author Share Posted June 6, 2006 (edited) Here: http://www.w3schools.com/htmldom/dom_obj_document.aspLook for what is in the column of "W3C" with getElementsByTagName("tag"), it says clearly "NO"But anyway, this is an old topic, and I just saw the answer I couldn't give you then :)What was this topic all about? [*Edit:]Now that I have a little more experience in the item of this topic, I do knwo how they all work, this topic may be closed. Edited June 6, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
aspnetguy Posted June 6, 2006 Share Posted June 6, 2006 Here: http://www.w3schools.com/htmldom/dom_obj_document.aspLook for what is in the column of "W3C" with getElementsByTagName("tag"), it says clearly "NO"You are correct, W3Schools does say that but that is for Level 1 DOM. In 2000 W3C made this a standard in Level 2 DOM. W3schools needs an update http://www.w3.org/TR/DOM-Level-2-Core/core.htmlWhat was this topic all about? If you don't know then nobody will...you started the topic Link to comment Share on other sites More sharing options...
Jack McKalling Posted June 6, 2006 Author Share Posted June 6, 2006 You are correct, W3Schools does say that but that is for Level 1 DOM. In 2000 W3C made this a standard in Level 2 DOM. W3schools needs an update http://www.w3.org/TR/DOM-Level-2-Core/core.htmlIf you don't know then nobody will...you started the topic <{POST_SNAPBACK}> Yeah, it needs an update lol But I think that would be easier said than done, right? Doesn't matter though, no need to rush :blink:I do know now what this is about, but Ive solved it troughout my experience (sounds awfully arrogant, lol) between then and now Link to comment Share on other sites More sharing options...
aspnetguy Posted June 6, 2006 Share Posted June 6, 2006 I do know now what this is about, but Ive solved it troughout my experience (sounds awfully arrogant, lol) between then and now smile.gifNo it doesn't sound arrogant (to me). It is just how it works. The longer you work at this the better you get and the more you learn.If I were to compare myself 2 years ago (before I got a job as a programmer) and myself today there is a huge diffrence. The cause being practice everyday. Link to comment Share on other sites More sharing options...
Jack McKalling Posted June 6, 2006 Author Share Posted June 6, 2006 (edited) You're right But it might have sounded as such if I explicitly didn't noticed *avoiding possible unneeded negative feelings*Anyway, the issue of this toipic is solved Edited June 6, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
aspnetguy Posted June 6, 2006 Share Posted June 6, 2006 I have closed it then Link to comment Share on other sites More sharing options...
Recommended Posts