jQuery click handlers to show one of four containers I have a navigation bar that when the list elements are clicked their respective body container appears and the other body containers disappear. 

navigation

&lt;ul&gt;
    &lt;li&gt;&lt;a id="home" href="#"&gt;&lt;img src="img/home-icon.png" alt="Home"&gt;HOME&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a id="about" href="#"&gt;&lt;img src="img/about-icon.png" alt="Home"&gt;ABOUT&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a id="projects" href="#"&gt;&lt;img src="img/projects-icon.png" alt="Home"&gt;PROJECTS&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a id="contact" href="#"&gt;&lt;img src="img/contact-icon.png" alt="Home"&gt;CONTACT&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


body containers:

&lt;div id="homeBodyContainer"&gt;home&lt;/div&gt;
&lt;div id="aboutBodyContainer"&gt;about&lt;/div&gt;
&lt;div id="projectsBodyContainer"&gt;projects&lt;/div&gt;
&lt;div id="contactBodyContainer"&gt;contact&lt;/div&gt;


JQuery:

$(document).ready(function () {
    $("#home").click(function(){
        event.preventDefault();
        $("#aboutBodyContainer").hide();
        $("#projectsBodyContainer").hide();
        $("#contactBodyContainer").hide();
        $("#homeBodyContainer").fadeIn(1500);
    });
    $("#about").click(function(){
        event.preventDefault();
            $("#homeBodyContainer").hide();
            $("#projectsBodyContainer").hide();
            $("#contactBodyContainer").hide();
            $("#aboutBodyContainer").fadeIn(1500);
    });
    $("#projects").click(function(){
        event.preventDefault();
        $("#homeBodyContainer").hide();
        $("#aboutBodyContainer").hide();
        $("#contactBodyContainer").hide();
        $("#projectsBodyContainer").fadeIn(1500);
    });
    $("#contact").click(function(){
        event.preventDefault();
        $("#homeBodyContainer").hide();
        $("#projectsBodyContainer").hide();
        $("#aboutBodyContainer").hide();
        $("#contactBodyContainer").fadeIn(1500);
    });
});


As you can see the functions are almost identical. Is there a way I can reduce the amount of code here?
Here you can write a simple logic to identify container div on the basis of anchor id.

Please see below code:

put class="container" for all container div, like below :

&lt;div id="homeBodyContainer" class="container"&gt;home&lt;/div&gt;
&lt;div id="aboutBodyContainer" class="container"&gt;about&lt;/div&gt;
&lt;div id="projectsBodyContainer" class="container"&gt;projects&lt;/div&gt;
&lt;div id="contactBodyContainer" class="container"&gt;contact&lt;/div&gt;


And jQuery is :

$(document).ready(function () {
    $("li a").click(function(){
        event.preventDefault();
        // hide all container div
        $(".container").hide();

        // get id of clicked anchor and create its corresponding container id
        var anchorId = $(this).attr('id');
        var containerId = anchorId+"BodyContainer";
        $("#"+containerId).fadeIn(1500);
    });

});


Note : It would be better idea to assign same class to anchor, so that if you have some other anchor available in your HTML then also you can easily bind click event to all desired anchor.

Example:

Assign class="anchorToClick" to all desired anchor tags

and jQuery will be like 

$(document).ready(function () {
        $(".anchorToClick").click(function(){
            // your stuff here
          });

    });