I am trying to implement a navigation sidebar on left with list of links(<a>
) such that on click of each links, corresponding <div>
will be loaded on right side.
When I have a function for onclick
property in <a>
. It gives me error on browser console.
Uncaught ReferenceError: callFunction is not defined
Here is my implementation:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
function callFunction(){alert("Load divs");}
});
</script>
<style>
div.container {
width: 100%;
border: 1px solid gray;
}
header, footer {
padding: 1em;
color: white;
background-color: powderblue;
clear: left;
text-align: center;
}
nav {
float: left;
max-width: 160px;
margin: 0;
padding: 1em;
}
nav ul {
list-style-type: none;
padding: 0;
}
nav ul a {
text-decoration: none;
}
article {
margin-left: 170px;
border-left: 1px solid gray;
padding: 1em;
overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>My Company</h1>
</header>
<nav>
<ul>
<li><a href="#" onclick="callFunction()">Link1</a></li>
<li><a href="#" onclick="callFunction()">Link2</a></li>
<li><a href="#" onclick="callFunction()">Link3</a></li>
</ul>
</nav>
<!--<div id="Link1" class="class1">
<h1>Link1</h1>
<p>Link1 detail</p>
</div>
<div id="Link2" class="class1">
<h1>Link2</h1>
<p>Link2 detail</p>
</div>-->
<footer>Copyright © myCompany</footer>
</div>
</body>
</html>
My requirement is to have a list of Links and s, where s should be hidden, and only be appeared when corresponding Links are clicked.