html - Change content when link is clicked, Javascript -
i had working on 1 site, , tried recreate it's not working... want have content in div change without loading, replacing content via javascript.
here's html:
<li><a onclick="mish()">click me</a></li> <div id="about"> <h2>im header.</h2> <p>and im paragraph!</p> </div>
and here's js, located in external .js file:
function mish() { document.getelementbyid("about").innerhtml='<h2>header i.</h2> <p>paragraph , too.</p>'; }
and linked line in head of html (i've tried in body):
<script type="text/javascript" src="script.js"></script>
again, copied pretty of code site did, still works, @ loss why 1 isn't working.
edit: here 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: , 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 header</h2> <p>and im paragraph</p> </div> </div><!-- end actual --> </div><!-- end content--> </div><!-- end crusty --> </body>
and triple edit show exact contents of .js file:
function mish() { document.getelementbyid("about").innerhtml = '<h2>header i.</h2>'+ '<p>paragraph , too.</p>'; }
the common practice in writing multi-line strings in javascript following. presently have newline within string (not escaped), not allowed in javascript.
function mish() { document.getelementbyid("about").innerhtml = [ '<h2>header i.</h2>', '<p>paragraph , too.</p>'].join('\n'); }
the main take-away newline can communicated \n
in javascript strings.
Comments
Post a Comment