I keep struggling with the .animate function

I keep stuggling with the animate function. in combination with the .toggle function. I simply try to make a div slide from right to left and visa versa on click. This is what I have:

Javascript:


	var w = $('.content').width();
	
  $('#toggle').toggle(function() {
    $('div.content').animate({left: -600}, 600, function(){
			$('#toggle').text("open");
		});
		return false;
  }, function() {
    $('div.content').animate({left: 0}, 900, function(){
		  $('##toggle'').text("close");
		});
		return false;
  });

HTML


<div id="content" class="content">
	<div class="header">
  	<div class="close"><a href="##" id="toggle">Close</a></div>
  	<h1>Title</h1>
	</div>
</div>

When opening the page the content div slide automatically to the left and the toggle anchor slides to the right. What am I doing wrong, and can someone please explain me the .animate/.toggle functions in more detail.

Thank you in advance

Hi donboe,

Which version of jQuery are you using?
jQuery’s Toggle Event function has [URL=“https://github.com/jquery/jquery-migrate/blob/master/warnings.md#jqmigrate-jqueryfntogglehandler-handler-is-deprecated”]been removed as part of version 1.9. which could account for your error.

Oh my. That was it indeed. I was struggling the entire morning. Thank you so much Pullo. :tup: