Binding to <a> or <form> elements' click events before jQM loads breaks navigation #1384

Closed
JangoSteve opened this Issue Apr 6, 2011 · 7 comments

Projects

None yet

3 participants

@JangoSteve

jQM AJAX navigation breaks if you bind handlers to the click events of any a or form elements with .live() or .delegate() before jquery.mobile-1.0beta-pre.min.js is included in the page. For example:

<script src="/javascripts/jquery.js" type="text/javascript" />
<script type="text/javascript">
  $('a').live('click', function() { console.log('hi'); });
  // or this to:
  $(document).delegate('a', 'click', function() { console.log('hi'); });
</script>
<script src="/javascripts/jquery.mobile-1.0beta-pre.min.js" type="text/javascript" />

However, this works fine:

<script src="/javascripts/jquery.js" type="text/javascript" />
<script src="/javascripts/jquery.mobile-1.0beta-pre.min.js" type="text/javascript" />
<script type="text/javascript">
  $('a').live('click', function() { console.log('hi'); });
</script>

Obviously, this code is an unrealistic example. However, it's not uncommon for jQuery plugins to use live or delegate, which means if you include such a plugin before jQuery Mobile, it breaks, but include the plugin after jQuery Mobile and it works.

Also, this bug did not exist in Alpha 4-pre, only in Beta-pre.

@jblas
jblas commented Apr 6, 2011

Hi @JangoSteve,

I can't tell when you pulled your source based on the names you've given ("Alpha 4-pre, Beta-pre). Have you tried this against our current HEAD? I ask because in Alpha 4 we were experimenting with triggering actions on 'a' tags via the new virtual events. This was landed just prior to us releasing Alpha 4, so I'm wondering if your Alpha 4-pre you refer to was before "fastclick" landed. We've since backed off because it causes some very peculiar problems. (See Issue 1331 for details)

@JangoSteve

Sorry, the latest version that I had experienced this with was as of this commit.

@toddparker

What is you use vclick instead of click?

@JangoSteve

Are you saying replace click with vclick in the other libraries, or in jQuery Mobile?

@jblas jblas was assigned May 2, 2011
@jblas
jblas commented May 2, 2011

@JangoSteve,

I just tried your test and it works on the HEAD ... it prints out both click 'hi' messages. Have you tried the latest source?

  • Kin
@JangoSteve

Hey sorry I've been absent. I'll pull down the new code into my project and try this again this weekend.

@toddparker

This should now be fixed in master.

@toddparker toddparker closed this Jun 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment