Jump to content

How to Style something based on ElementID?


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...