unreal Posted January 24, 2007 Share Posted January 24, 2007 Hi all,I've searched the forums already but did not find anything that really answers this.So the way W3cschool teaches to get a value of an element shown is like such function getmessage(){document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; and then we do a <p><span id="to"></span> But how do I go about display 2 or more of values from different nodes of the elements with the same tag?W3cschool uses this method // documentElement always represents the root nodevar x=doc.documentElement;document.write("Text of first child element: ");document.write(x.childNodes[0].childNodes[0].nodeValue);document.write("<br />");document.write("Text of second child element: ");document.write(x.childNodes[1].childNodes[0].nodeValue);</script> That would work but how do i go about having to output by using <SPAN id> ? and not using document.write in Java.That would be more flexible when it comes to dealing with css as well.Do i do a var=secondnode=document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;actually i tried that.. din't work.Hope to see some help .. Thanks in advance Link to comment Share on other sites More sharing options...
xpriens Posted January 24, 2007 Share Posted January 24, 2007 hey why not try to write a for/while loop for the same to span across different elements var i=0;for (i=0;i<10;i++){document.write(x.childNodes.childNodes[0].nodeValue);}Also, u can check for the total childnodes and then loop in accordingly[]..hope this helps.... Link to comment Share on other sites More sharing options...
unreal Posted January 24, 2007 Author Share Posted January 24, 2007 Thanks for replying.yeah like i said. i din't wanna use document.writeanyway i got it working already.I just change the ElementById to anything.. it can be changed and use span to link to that.Messy though.. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now