H
H
Hazrat Hajikerimov2014-10-24 14:50:34
JavaScript
Hazrat Hajikerimov, 2014-10-24 14:50:34

Why does the event object need to be passed as a function argument in Firefox when using jQuery?

Code example:

$('.block').click(function(){
        var is = $(this);

        if(!is.hasClass('active')){
            is.addClass('active')
            event.stopPropagation();
        }
    });

 On web-kit engines, everything works fine, it’s clear that the event is a global object, but it refuses to work in FireFox, but if you insert the event object into the argument of the anonymous function:
$('.block').click(function(event){
 // тут все работает
})

FireFox is up and running!

What can be wrong?

UPD: maybe it's because you need to specify event as window.event?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Sydorenko, 2014-10-24
@hazratgs

The first piece of code is not correct. The use of an uninitialized variable, or rather the use of the window.event variable, which may not be initialized. Whereas jQuery explicitly states the presence of the event parameter in the click callback , which is where the event object comes in.
So firefox, in this case, protected you from incorrect code. I think using use strict; in any browser would not allow you such liberties.

S
Sergey delphinpro, 2016-12-09
@letehaha

Place .main-item after .slider.active, change the order with flex and refer to it with a plus sign.
~ also works only on subsequent elements (and + only on the next one ) UPD https://jsfiddle.net/1whm1g4o/3/

U
ukoHka, 2016-12-09
@ukoHka

Alternatively, you can set active not only to .slider, but also to .main-item or even to the parent li.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question