Hi, stuck and haven't been able to find a solution.

Problem is pretty simple, I'm importing XML content using Javascript in an HTML page. I managed to display the XML elements and positioned it correctly using a table. Now I wanted to style the fonts of each element extracted specifically.

Here is the code so far:

<script type="text/javascript">
                        if (window.XMLHttpRequest)
                          {// code for IE7+, Firefox, Chrome, Opera, Safari
                          xmlhttp=new XMLHttpRequest();
                          }
                        else
                          {// code for IE6, IE5
                          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                          }
                        xmlhttp.open("GET","news.xml",false);
                        xmlhttp.send();
                        xmlDoc=xmlhttp.responseXML;
        
                        var x=xmlDoc.getElementsByTagName("story");
                        for (i=0;i<x.length;i++)
                          {
                              document.write("<tr><td>");
                              document.write("</td><td>");
                              document.write("<table border='0'>");
                              document.write("<tr><td>");
                              document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
							  document.write("</td></tr><tr><td>");
                              document.write(x[i].getElementsByTagName("date")[0].childNodes[0].nodeValue);
                              document.write("</td></tr><tr><td>");
                              document.write(x[i].getElementsByTagName("content")[0].childNodes[0].nodeValue);
                              document.write("</td></tr>");
                              document.write("</table>");
                              document.write("</td></tr>");
                          }
						  
                	</script>

I have been trying to solve it with the use of:

document.getElementByTagName("title").style.font="italic bold 18px arial,serif";

But is not the solution, could someone advise me appropriately please.

Ok, silly question. Will answer my own question.

document.write("<h2 style='color: #e32b21'>");
                              document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
							  document.write("</h2>");

I did previously try to style it within the getElementsByTagName, which wasn't working. Now works :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.