1

I was using jquery 1.3 on my website. Today I updated it to newest 1.9 and my toggle/animate script stopped to work.

The code looks like that:

<a href="javascript: void(0);" id="toggler">Show more</a>
<div id="tcontent"> … </div>

$(document).ready(function() {                      
    $('#toggler').toggle(
    function() {
        $('#tcontent').animate({height: "70"}, 800);
    },
    function() {
        $('#tcontent').animate({height: "6"}, 800);
    });
});

What is wrong with this code? When I include back jquery 1.3 to my html everything works fine.

Barlas Apaydin
  • 7,233
  • 11
  • 55
  • 86
gordonek
  • 137
  • 1
  • 2
  • 13
  • I happened to answer this 10 minutes ago: http://stackoverflow.com/questions/14603775/jquery-adding-toggle-to-a-makes-it-disappear/14603971#14603971. – pimvdb Jan 30 '13 at 12:35
  • possible duplicate of [Where has fn.toggle( handler(eventObject), handler(eventObject)...) gone?](http://stackoverflow.com/questions/14301935/where-has-fn-toggle-handlereventobject-handlereventobject-gone) – mplungjan Jan 30 '13 at 12:35

2 Answers2

2

Try this

<a href="#" id="toggler" data-show="no">Show more</a>

and

$(function() {                      
  $('#toggler').on("click",function(e) {
      if ($(this).data("show")=="no") {
        $('#tcontent').animate({height: "70"}, 800);
        $(this).data("show","yes");
      }   
      else {
        $('#tcontent').animate({height: "6"}, 800);
        $(this).data("show","no");     
      }
  });
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0
$('#toggler').click( function() {
    $('#tcontent').toggle(
        function()
        {
            $(this).animate({height: "70"}, 800);
        },
        function()
        {
            $(this).animate({height: "6"}, 800);
        }
    );
});
Tom
  • 12,776
  • 48
  • 145
  • 240