简体   繁体   中英

Issues with jQuery 1.9 and slideToggle

So, I'm not sure what happened, but I had his javascript function that shows/hides a div and then changes the + to a - when it's triggered.

This is what I have:

 $('.internal').hide();

$('.slider').click(function() {
    $(this).next('.internal').slideToggle();
}).toggle(function() {
    $(this).children("span").text("[-]");
}, function() {
    $(this).children("span").text("[+]");
    return false;
});

This apparently works great with jQuery's 1.8 library, but when I switch it to 1.9 or above it just slides everything up and makes everything dissapear.

Not too sure what happened or what was changed between 1.8 and 1.9 and I'm not sure what I need to fix to make it work again.

I made a fiddle: http://jsfiddle.net/9LcXk/

Which is using 1.8.3 at the moment. But if you change it to 1.9 and re-run it, you'll see what happens.

Use the click event instead:

DEMO

$('.slider').click(function () {
    $(this).next('.internal').slideToggle();
    this.toggle = !this.toggle;
    $(this).children("span").text(this.toggle ? "[-]" : "[+]");
    return false;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM