I had this working on one site, and I tried to recreate it but now it's not working... I want to have content in a div change without loading, by replacing the content via Javascript.
Here's the HTML:
<li><a onclick="mish()">Click me</a></li>
<div id="about">
<h2>Im a header.</h2>
<p>And Im a paragraph!</p>
</div>
And here's the JS, located in an external .js file:
function mish()
{
document.getElementById("about").innerHTML='<h2>Header am I.</h2>
<p>Paragraph am I and too.</p>';
}
And they are linked with this line in the head of the html (I've also tried in the body):
<script type="text/javascript" src="script.js"></script>
Again, I copied pretty much all of the code from another site I did, which still works, so I am very much at a loss as to why this one isn't working.
EDIT: Here is the head section:
<head>
<title>Shaq</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="script.js"></script>
</head>
DOUBLE EDIT: and the whole body:
<body>
<div class="crusty">
<div class="content">
<nav>
<ul>
<li><a onclick="bout()">Click Me</a></li>
<li><a onclick="mish()">Click Me</a></li>
</ul>
</nav>
<div class="actual">
<div id="about">
<h2>Im a Header</h2>
<p>And Im a Paragraph</p>
</div>
</div><!-- end actual -->
</div><!-- end content-->
</div><!-- end crusty -->
</body>
And TRIPLE EDIT to show exact contents of .js file:
function mish() {
document.getElementById("about").innerHTML = '<h2>Header am I.</h2>'+ '<p>Paragraph am I and too.</p>';
}
in the `innerHTML` statement? Javascript doesn't like those. Either make it all one line, or make it `document.getElementById("about").innerHTML='
Header am I.
' + 'Paragraph am I and too.
';` with theline on a new line.
– Luke Shaheen Jul 18 '13 at 02:13Header am I.
'+ 'Paragraph am I and too.
'; } with 'Header am I.
Paragraph am I and too.
' not that it makes huge difference but just to make it clear and you don't need + anyways. – Learner Jul 18 '13 at 03:04