I am working on a small little text box that will actively display different text without reloading the page. I use javascript to insert paragraphs of text based of which link the user clicks on. It works, however, i want to also insert style attributes to the dynamically inserted content. I want to do this because the background of the div is going to be black.
Here is my JS
function navClicked(x){
//alert("function activated");
//alert(x);
if (x == "aboutButton"){
//alert("About Button");
document.getElementById('information').innerHTML = "About Click";
}
else if(x == "faqButton"){
//alert("FAQ Button");
document.getElementById('information').innerHTML = "FAQ Click";
}
else if(x == "servicesButton"){
//alert("Services Button");
document.getElementById('information').innerHTML = "Services Click";
}
else{
//alert("Contact Button");
document.getElementById('information').innerHTML = "Contact Click";
}
}
Here is the html that goes with it
<body>
<div id="navigation">
<table cellpadding="5">
<tr>
<td>
<a onClick="navClicked('aboutButton');" style="cursor: pointer; cursor: hand;">ABOUT ATS</a>
</td>
</tr>
<tr>
<td>
<a onClick="navClicked('faqButton');" style="cursor: pointer; cursor: hand;">FAQ</a>
</td>
</tr>
<tr>
<td>
<a onClick="navClicked('servicesButton');" style="cursor: pointer; cursor: hand;">SERVICES</a>
</td>
</tr>
<tr>
<td>
<a onClick="navClicked('contactButton');" style="cursor: pointer; cursor: hand;">CONTACT</a>
</td>
</tr>
</table>
</div>
<div id="information">
<p>
content
</p>
</div>
</body>
and finally the CSS
<style>
body, div, h1, h2, h3, h4, h5, h6, p, ul, img {margin:0px; padding:0px; }
p
{
color:white;
}
#navigation
{
height:145px;
float:left;
width:155px;
background:grey;
}
#navigation table
{
margin-left:auto;
margin-right:auto;
color:white;
}
#information
{
height:145px;
float:left;
width:290px;
background:black;
}
</style>
The final products works. However, whenever new text gets inserted to the box, it becomes black. And then you cannot read the text.
Here is a jsFiddle http://jsfiddle.net/9xahg/
although it doesnt work in fiddle and im not sure why. But regardless, it works as intended in all browsers with the exception that you cannot read the new text.
How can I fix this?