Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#13395 closed bug (notabug)

toggle function goes wrong - jQuery 1.9.1

Reported by: antoinechailloux@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

When using the toggle function in jQuery 1.9.1, first target element seems to hide away, the "toggle back" function then executes by itself, without clicking.

The error occures using jQuery 1.9.1 and 1.9.1.min. I report a bug as previous releases (1.8.3) don't seem to have that problem. No matter what browser I am using, the toggle function seems to do by it's own.

-- test Case -- http://jsfiddle.net/DCCMD/

:)

$("#myElement").toggle( function() {

something here

}, function() {

something else alert('toggled');

}); the "toggled" alert executes on page load, without clicking

Change History (6)

comment:1 Changed 6 years ago by dmethvin

Resolution: notabug
Status: newclosed

comment:2 Changed 6 years ago by c00kiemon5ter

.toggle() was really useful for certain stuff. what is the recommended alternative now ?

comment:3 Changed 6 years ago by dmethvin

Use the jQuery Migrate plugin, or copy/paste the lines out and use it that way. I don't know about it being useful, the times I've seen it used are things like this:

$(".header").toggle(
  function(){
    $(".feedback").show();
  },
  function(){
    $(".feedback").hide();
  }
);

Which could easily be rewritten as:

$(".header").on("click", function() {
  $(".feedback").toggle();
});

comment:4 Changed 6 years ago by cristianromagnoli@…

Hi guys, but what if you have the next? How do you rewrite this?:

http://jsfiddle.net/cristianromagnoli/tuxfz/

I cannot find a way to rewrite this in an alternative way, not using toggle(function, function).

Thanks!

comment:5 Changed 6 years ago by dmethvin

This is the bug tracker, and you're looking for programming help. Use the jQuery Migrate plugin or ask for help on a forum, there are several good solutions.

comment:6 Changed 6 years ago by synx

is not supper! but i use this code

var toggle = 0; $("#borderdroite_button").on("click", function() { switch (toggle) {

case (0):

$("#borderdroite").hide();

toggle = 1; break;

case (1):

$("#borderdroite").show();

toggle = 0; break;

} });

Note: See TracTickets for help on using tickets.