I have a site that shows system status that has a colored bar behind it depending on the health of the system it displays. My HTML that uses the jQuery is:
<script>
function myExampleSite()
{
var myURL = window.location.href;
var dashIndex = myURL.lastIndexOf("-");
var dotIndex = myURL.lastIndexOf(".");
var result = myURL.substring(dashIndex + 1, dotIndex);
return result;
}
var exampleSite = myExampleSite();
</script>
<script>
var root = null;
$(document).ready(function ()
{
$.get("Status_Pages.xml",
function (xml)
{
root = $(xml).find("site[name='" + exampleSite + "']");
var status = $(root).find("systemStatus");
var color = status.attr("color");
$("#status").html(status.text());
$("#status").attr("color", color);
result = $(root).find("networkNotes");
$("#networkNotes").html($(result).text());
result = $(root).find("headerImage");
$("td#headerImage").html($(result).text());
....etc etc
});
});
</script>
My XML file looks like this.
<sites>
<site name="Template">
<headerImage>images/template-header.png</headerImage>
<productVersion>[Version goes here]</productVersion>
<systemStatus color="green">Normal</systemStatus>
<networkNotes>System status is normal</networkNotes>
</site>
</sites>
I have several <site>s that all have their own data that will populate different areas of individual sites. I've ran into a snag though.
The way I am displaying my status currently looks like this:
<tr>
<td class="table_header">
Current System Status
</td>
</tr>
<table><tr>
<td id="status"></td>
</tr></table>
<tr>
<td class="table_header">
Network Notes
</td>
</tr>
Right now it's hard-coded to show the system status with either a red, green, or yellow bar behind the text to indicate the health of the system, but I need to make able to read the XML value for that site.
The tricky part is that I am also using data from a CSS for this particular portion of the site. The CSS code relevant to this is (there is one for green, yellow, and red):
#status[color=green] {
color: white;
text-align: left;
background: url(images/greenbar.jpg) no-repeat;
}
#status[color=yellow] {
color: black;
text-align: left;
background: url(images/yellow.jpg) no-repeat;
}
#status[color=red]{
color: black;
text-align: left;
background: url(images/red.jpg) no-repeat;
}
**How can I read in the system status string, along with the element's attribute of color to populate my HTML so that each site has a different image depending on what's in the XML? **
I have tried the above and it gives a color background to the text, not the image url background.
And it reads the correct status but the image never appears behind it.
#normal_statusis an ID rather than a class, and as per HTML spec, no two elements should have the same ID.#normal_status. I showed what was in the CSS as well as the HTML. The only place it's used in the HTML is what I showed before the CSS code block.green==normal,red==downor something?