Skip to content
This repository

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

Closed
JangoSteve opened this Issue April 05, 2011 · 7 comments

3 participants

Steve Schwartz Kin Blas Todd Parker
Steve Schwartz

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.

Kin Blas
jblas commented April 06, 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)

Steve Schwartz

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

Todd Parker

What is you use vclick instead of click?

Steve Schwartz

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

Kin Blas
jblas commented May 02, 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
Steve Schwartz

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

Todd Parker

This should now be fixed in master.

Todd Parker toddparker closed this June 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.