Kumaresh Kumaresh - 4 months ago 17
jQuery Question

Slide out div using jquery

Recently I found a solution to slide out div on click in stack overflow answers .

They posted the link

jsfiddle.net/LU8En/
.

In the jsfiddle answer they used jquery 1.7.2. Its not working with jquery 1.9.1. I don't know the reason..? Any Idea..?

Answer

Try this: Fiddle

$(function () {
  $("#clickme").click(function () {
    if($(this).parent().css("right") == "-280px"){
    $(this).parent().animate({right:'0px'}, {queue: false, duration: 500});
  }
  else {
    $(this).parent().animate({right:'-280px'}, {queue: false, duration: 500});
  }
  });
});

The .toggle(function, function, ... ) was removed from version 1.9

See the jQuery Core 1.9 Upgrade Guide

A better approach: Sample 2

$(function () {
   $("#clickme").click(function () {
       if($(this).parent().hasClass("popped")){
       $(this).parent().animate({right:'-280px'}, {queue: false, duration: 500}).removeClass("popped");
   }else {
       $(this).parent().animate({right: "0px" }, {queue: false, duration: 500}).addClass("popped");}
   });
});