1

I am try to build a menu for my personal webpage which would load a html file into a contents div when I click on the corresponding link on the menu. The layout is what I want, but unfortunately I cannot get the click event to work. This is what I have:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Jorge Martins' HomePage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" href="styles.css" media="all" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <script language="javascript">
$(document).ready(function () {
    $('li.about').click(function(){
        $('#content').load( 'about.html' );
    });
    $('#research').click(function(){
        $('#content').load( 'about.html' );
    });
});
    </script>
</head>
<body>
    <div>
    <ul class="menu">
        <li id="home">Home</li>
            <li class="about">About me</li>
            <li id="research">Research</li>
        <li id="publications">Publications</li>
    </ul>
</div>
    <div id="content">
    </div>

</body>
</html>

and the css:

ul.menu {
margin: 0;
padding: 0;
float:left;
width: 15%;
margin: 10px;
}


ul.menu li {
list-style: none;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:24px;
font-weight:bold;
color: #555;
height: 32px;
voice-family: "\"}\""; 
voice-family: inherit;
height: 24px;
text-decoration: none;
}   


ul.menu li:hover {
color: #FFF;
/*padding: 0px 0 0 0px;*/
}

#content {
width: 75%;
float:left;
margin: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 16px;
font-weight: bold;
color: #555;
}

Any idea on what I've done wrong?

Thanks.

EDIT: Removed extra tab as per Joe's comment.

jorgehumberto
  • 1,047
  • 5
  • 15
  • 33

1 Answers1

7

You have an extra close tag.

$(document).ready(function () {
        $('li.about').click(function(){
            $('#content').load( 'about.html' );
        });
    //remove this });
        $('#research').click(function(){
            $('#content').load( 'about.html' );
        });
    });
Joe
  • 112
  • 5
  • Hi jorge, which part of the codes did not work? The clicking event is working fine as tested. – Joe Feb 08 '15 at 08:12
  • Basically when I click on the menu link nothing happens and the 'about.html' file does not get loaded into the contents div. – jorgehumberto Feb 08 '15 at 08:14
  • As the file used ajax, you have to upload your files and test it on a server. Otherwise, you can try to disable the web security of chrome browser and test it locally. – Joe Feb 08 '15 at 08:21
  • @jorgehumberto Here's a link on how to disable web security of chrome browser: http://stackoverflow.com/questions/24290149/creating-google-chrome-shortcut-with-disable-web-security – Joe Feb 08 '15 at 08:23
  • So that was it! I tested it on firefox and worked like a charm! Many thanks! – jorgehumberto Feb 08 '15 at 08:30