Jump to content

How to Style something based on ElementID?


XHTMLboy

Recommended Posts

Hello thier, I've been trying to get something working and now it does. It's just I cannot style it with CSS. What I want to style is the XML that is being pulled in. Here's my code.

 <!DOCTYPE html><html lang="en"><head>    <title>XML Import</title>    <style type="text/css">    }    </style>    </head><body>    <script type="text/javascript">    function xml_get(){                if (window.XMLHttpRequest) {                        xmlhttp = new XMLHttpRequest();}        else {                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");                }                    xmlhttp.open("GET", "martyn.xml", false);        xmlhttp.send();        xmlDoc = xmlhttp.responseXML;                    var x = xmlDoc.getElementsByTagName("user");                    for (i=0; i<x.length; i++) {                            document.write(x[i].getElementsByTagName("uID")[0].childNodes[0].nodeValue);            document.write("<br />");                            document.write(x[i].getElementsByTagName("privilege")[0].childNodes[0].nodeValue);            document.write("<br />");                            document.write(x[i].getElementsByTagName("last_login")[0].childNodes[0].nodeValue);            document.write("<br />");                            document.write("<br />");}}        </script>        <input type="button" onClick="xml_get()" value="XML Import!" />    </body></html> 

Thanks for taking a look :)

Link to comment
Share on other sites

The XML is just data, it's not on the page so it cannot be styled. Put the data into an HTML element and then style the HTML element using the Style Object. You're going to have to drop the document.write() method too, use innerHTML or text nodes.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...