Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13985 closed bug (notabug)

Two versions of jQuery and the $.noConflict causes some weird behavior on link clicks

Reported by: netlovers Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.1
Keywords: Cc:
Blocked by: Blocking:

Description

I created a sample here: http://jsfiddle.net/3ksqX/3/ The problem is, when I call .click() on a link with the noconflicted version of jquery, the previously attached event doesn't run (.trigger('click') doesn't work either).

If I do the same with a button, then the counter increases (in the example).

I did some digging, and this is the line, where everything stops: https://github.com/jquery/jquery/blob/master/src/event.js#L564

What is the expected behavior?

Change History (2)

comment:1 Changed 7 years ago by dmethvin

Resolution: notabug
Status: newclosed

This is expected behavior. Updated test case: http://jsfiddle.net/3ksqX/5/

Each copy of jQuery has its own event list. When you manually .trigger("click") or .click() the copy of jQuery does most of the work. It has to:

  • Start at the event target (the innermost element clicked)
  • Run any associated event handlers that this copy of jQuery knows about; it doesn't know about lists held by other copies but it does know about the inline onclick handlers.
  • Bubble up the DOM repeating the process until it reaches window.
  • For all DOM methods except click, run the DOM method if the default action has not been stopped with event.preventDefault(). See #12652 for why this exception exists.

If you need to bridge two copies of jQuery you could a click handler on one copy that triggered a similar click on the other jQuery copy. Really though, two copies of jQuery in a page should be avoided.

comment:2 Changed 7 years ago by netlovers

I saw the other ticket, but this really seems inconsistent to me, because it works with other elements, but not with links. And it is sad, but I don't really have any knowledge about the other jQuery versions. I mean, I could write some

if (!jQuery) { doc.write('<script src="own-jquery.js"></scr'+'ipt>'); }

code but it seemed a bad idea. And then I have to put up with all the old versions of jQuery's quirks, not to mention if for some reason they use $.noConflict too, when attaching event listeners, than there is no way of triggering a click event, that runs all the handlers that were attached is any way. At least not with jQuery. This is so sad.

But, thank you really!

Note: See TracTickets for help on using tickets.