Can not get div to animate from left to right in jQuery


I have a list which serves as a menu. Every time user clicks on one of the elements in the list, I want a more detailed div to slide in from left to right.

So if the user was to click menu item A first, A slides from left to right. If the user then clicks B, A slides out from right to left (disappears off screen) and B slides in.

I searched for this problem and found this post. I incorporated the code from the jsfiddle, but it didn't work. No errors are being shown in the js log in Chrome debugging tool. Nothing happens when I click any item from the menu. What am I doing wrong?

 <div class="project">
        <ul id="project_menu" class="project_menu">
            <li id="menu-php-mysql" data-projectID="php-project">PHP/MySQL</li>
            <li id="menu-nodejs" data-projectID="node-project">NodeJS</li>
            <!-- more code -->
        <div class="project-detail">
            <div id="php-project">
                <i class="ion-ios-close-empty close-icon js-close-icon"></i>
                <div classs="project-text">
                    <!-- data about project -->
            <div id="node-project">
                <i class="ion-ios-close-empty close-icon js-close-icon"></i>
                <div classs="project-text">
                    <!-- data about project -->
            <!-- and so on.. -->

#php-project {
    background-color: #9b59b6;
    margin: 30px;
    display: none;

$(document).ready(function() {

    itemsToRender = [];

    $('ul#project_menu li').click(function(e) {

        menuItemId = (;


        $(getProjectId(menuItemId)).css('display', 'inline');

        var value = $(getProjectId(menuItemId)).css('right') === '100px' ? '-100px' : '100px';
            right: value
        }, 800);


function getProjectId(menuItemId) {

    if (menuItemId.indexOf('php') > 0) {

        return '#php-project';

    } else if (menuItemId.indexOf('node') > 0) {

        return '#node-project';

    } else if (menuItemId.indexOf('angular') > 0) {

        return '#angular-project';

    } else if (menuItemId.indexOf('mean') > 0) {

        return '#mean-project';


Update1: @user5325596 pointed out that my display property for the detail div was set to none, so I fixed that by adding the following:

$(getProjectId(menuItemId)).css('display', 'inline-block');

right after $('.common').hide().

Now, I can see the detail div when I click on the menu item, but it does not animate.

Update2: I have uploaded a jsFiddle, it includes the jquery animation that I am successfully using (fadeIn, which is commented out), as well as the code suggested by elchininet.

Not sure if this is what you need or not

JS Fiddle - updated 2

// initializing
var prevID = '',
    divs = $('.sliding-divs');

$("li").on("click", function() {
  var theID, theDiv, theDivW, theCenter;

  // get the id letter from the li, then pick the corresponding sliding
  // div depending on its value.
  theID = $(this).attr('id');
  theID = theID.replace('li-', '');
  theDiv = $('#div-' + theID);

  // get the divs width to slide it into the center of the view
  theDivW = theDiv.width();
  theCenter = $(window).width()/2 - theDivW/2;

  // if the user didn't click the link which its slide already
  // in the view, this to avoid sliding out and in same div.
  if(theID != prevID){
      if (prevID == '') {

      // if we don't have a previously slided in div, we just slide
      // the just click link's div into the view
      theDiv.animate({'left': theCenter}, 1000);
    } else {

      // animated the previous div to the right out of the view, then
      // move all divs to their original position out from the left
      // this is because if we don't do this, an already slided div
      // will later be slided in from right instead in from left
      // because we have already changed its position.
      // slide the just clicked link's div into the view from left
      $('#div-' + prevID).animate({'left': '110%'}, 800);
      divs.css({'left':-(theDivW + 100)});
      theDiv.animate({'left': theCenter}, 1000);

  // change the value of the id representing previously slided in div
  prevID = theID;
body {
  overflow-x: hidden;

ul {
  list-style: none;
  padding: 0;

li {
  width: 100px;
  height: 25px;
  margin: 2px 0;
  color: white;
  padding: 3px;
  text-align: center;
  background-color: green;

.sliding-divs {
  position: absolute;
  width: 500px;
  line-height: 250px;
  background-color: orange;
  font-size: 30px;
  border: 2px gold solid;
  text-align: center;
  display: inline-block;
  top: 150px;
  left: -510px;
<script src=""></script>
  <li id="li-A">item 1</li>
  <li id="li-B">item 2</li>
  <li id="li-C">item 3</li>
  <li id="li-D">item 4</li>
<div class="sliding-divs" id="div-A">
<div class="sliding-divs" id="div-B">
<div class="sliding-divs" id="div-C">
<div class="sliding-divs" id="div-D">