最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery SlideToggle() Not Working in FireFox, Works in Chrome - Stack Overflow

programmeradmin1浏览0评论

My code is this:

jQuery('.cart-module .cart-heading').bind('click', function() {
    if (jQuery(this).hasClass('active')) {
        jQuery(this).removeClass('active');
    } else {
        jQuery(this).addClass('active');
    }

    jQuery(this).parent().find('.cart-content').slideToggle('slow');
});
//--></script> 

You can test it for yourself by quickly adding a product to your cart like this and going to the shopping cart here .

When you click "Estimate Shipping & Taxes," it should display the DIV underneath of it. However, it only works in Chrome and not in Firefox. What can I do to fix this?

Thanks.

My code is this:

jQuery('.cart-module .cart-heading').bind('click', function() {
    if (jQuery(this).hasClass('active')) {
        jQuery(this).removeClass('active');
    } else {
        jQuery(this).addClass('active');
    }

    jQuery(this).parent().find('.cart-content').slideToggle('slow');
});
//--></script> 

You can test it for yourself by quickly adding a product to your cart like this https://muddydogcoffee./teas/176-organic-crimson-berry-fruit-tisane?device=iphone and going to the shopping cart here https://muddydogcoffee./shopping-cart.

When you click "Estimate Shipping & Taxes," it should display the DIV underneath of it. However, it only works in Chrome and not in Firefox. What can I do to fix this?

Thanks.

Share Improve this question asked Aug 7, 2012 at 23:23 user1477388user1477388 21.5k33 gold badges151 silver badges275 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I had the same problem before, I haven't really understood why it happens but I found a workaround for it.

I am not sure if it will also work for you but what I did is I removed the display:none in the stylesheet and just added it inline in the html.

If anyone could explain the strange behavior it will really be helpful though.

Add event.preventDefault(); and event.stopPropagation(); for this to work in all browsers including Firefox. See Snippet below:

jQuery('.cart-module .cart-heading').bind('click', function(e) {
    e.preventDefault();
    e.stopPropagation();
    if (jQuery(this).hasClass('active')) {
        jQuery(this).removeClass('active');
    } else {
        jQuery(this).addClass('active');
    }
 jQuery(this).parent().find('.cart-content').slideToggle('slow');
});

Have you tried :

$(document).ready(function() {
   // put all your jQuery goodness in here.
 });
发布评论

评论列表(0)

  1. 暂无评论