1

I have a jQuery function like this;

$('#mybutton').toggle(function() {
  alert("a");
}, function() {
  alert("b");
});

This was working fine with jQuery 1.3.2 . Recently I've upgraded jQuery to 1.11.0 . Then the page alerts b immediately after page load, and the button is disappearing. How can I fix this?

Here are the demos;

Old and new.

halfer
  • 19,824
  • 17
  • 99
  • 186
Alfred
  • 21,058
  • 61
  • 167
  • 249
  • what button is disappearing? – davidkonrad Apr 12 '14 at 18:22
  • @davidkonrad: He's talking about the button to which the handlers were intended to be bound. The one with the ID `mybutton`. Because `.toggle()` can no longer be used for event handers, the button simply gets hidden. The two answers below explain more, though for some reason they were both downvoted. – cookie monster Apr 12 '14 at 18:52

1 Answers1

-1

Looks like you're trying to use the toggle event, which was deprecated in jQuery 1.8 and removed on jQuery 1.9. The new toggle function has many different overloads, but none that behaves like the old one. Take a look at it and choose the one that suits you the most. For example, you could do something like this:

$('#mybutton').click(function () {
   if($('element').is(':visible')) {

    } else {

    }
});
Aditya
  • 4,453
  • 3
  • 28
  • 39