spl1n
spl1n

Reputation: 69

jquery event causes window refresh

I have backbone view and click events, which are supposed to call functions

events{
       "click .class": "myFunction"

}

the matter is, that some events just do what they are supposed to do, and others result in window refresh (e.g. when I am at the middle of the page content it throws me to the top of the page)

jquery 1.11 deals with these event differently.

at the place

  // Triggered event must either 1) have no
                                // namespace, or
                                // 2) have namespace(s) a subset or equal to
                                // those in the bound event (both can have
                                // no namespace).

normal event bubbles up though

while ((matched = handlerQueue[i++])
                                && !event.isPropagationStopped()) {
                            event.currentTarget = matched.elem;

                            j = 0;
                            while ((handleObj = matched.handlers[j++])
                                    && !event
                                            .isImmediatePropagationStopped()) 

and just return event.result;

events, that refresh window enter this block:

// Triggered event must either 1) have no
                                    // namespace, or
                                    // 2) have namespace(s) a subset or equal to
                                    // those in the bound event (both can have
                                    // no namespace).
                                    if (!event.namespace_re
                                            || event.namespace_re
                                                    .test(handleObj.namespace)) {

                                        event.handleObj = handleObj;
                                        event.data = handleObj.data;

                                        ret = ((jQuery.event.special[handleObj.origType] || {}).handle || handleObj.handler)
                                                .apply(matched.elem, args);

maybe anyone have faced this problem...

Upvotes: 2

Views: 309

Answers (2)

lyoung
lyoung

Reputation: 427

Where you define your function:

myFunction: function(event){ //<--make sure you have the "event" argument
    event.preventDefault(); // <--Add this statement in your function

}

Upvotes: 1

opticon
opticon

Reputation: 3594

Are any of the elements that trigger events <a> tags? Maybe with an SRC of "#"? If so, erase the SRC value and ensure that something like e.preventDefault is associated with the event.

Upvotes: 3

Related Questions