This repository
This repository
All repositories
Back to issue list Issue #1384
Closed

7 comments


Labels
  • 4 - High
JangoSteve opened this issue

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

No milestone
jblas is assigned

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.

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)

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

What is you use vclick instead of click?

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

@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

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

This should now be fixed in master.

Closed

toddparker closed the issue

Sign up for free to join this discussion on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.