Skip to main content

Bug Tracker

Side navigation

#13395 closed bug (notabug)

Opened February 05, 2013 07:18PM UTC

Closed February 05, 2013 07:20PM UTC

Last modified July 01, 2013 10:18AM UTC

toggle function goes wrong - jQuery 1.9.1

Reported by: antoinechailloux@hotmail.fr 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

Attachments (0)
Change History (6)

Changed February 05, 2013 07:20PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

Changed February 07, 2013 01:53PM UTC by c00kiemon5ter comment:2

.toggle() was really useful for certain stuff.

what is the recommended alternative now ?

Changed February 07, 2013 01:57PM UTC by dmethvin comment:3

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();
});

Changed June 29, 2013 08:18PM UTC by cristianromagnoli@gmail.com comment:4

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!

Changed June 30, 2013 01:21AM UTC by dmethvin comment:5

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.

Changed July 01, 2013 10:18AM UTC by synx comment:6

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;

}

});