简体   繁体   中英

Jquery not working while browsing with Firefox

Hello I'm using this code:

$("#cart").click(function () {
    if ($(event.target).closest('.content').length > 0) return false;
    $('#cart').load('index.php?route=module/cart #cart > *');
    var e = window.event || e;
    $("#cart").toggleClass("active");
    e.stopPropagation();
    $(document).click(function (e) {
        $("#cart").removeClass("active");
        $('#cart').live('mouseleave', function () {
            // Code Here
        });
    });
});

It works just fine in Chrome but when testing it in Firefox it doesn't work. The line that doesn't work is:

if ($(event.target).closest('.content').length>0) return false; 

Why does this work in Chrome but not in Firefox ?

You didn't pass event argument

try like this

$("#cart").click(function(event) {
  // now put your code here
}

You forgot to add event as an argument for your listener.

$("#cart").click(function (event) {
    if ($(event.target).closest('.content').length > 0) return false;
    $('#cart').load('index.php?route=module/cart #cart > *');
    var e = window.event || e;
    $("#cart").toggleClass("active");
    e.stopPropagation();
    $(document).click(function (e) {
        $("#cart").removeClass("active");
        $('#cart').live('mouseleave', function () {
            // Code Here
        });
    });
});

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