Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Simply move the <code>click</code> event handler code outside of the <code>pageinit</code> event handler code like this:</p> <pre><code>$( document ).delegate( "#page", "pageinit", function() { }); $(document).delegate('.eb', 'click', function() { var id = $('.eb').attr('id'); var to = $('#recipient').val(); var message = $('#email').html(); var atpos = to.indexOf("@"); var dotpos = to.lastIndexOf("."); if (atpos &lt; 1 || dotpos &lt; atpos + 2 || dotpos + 2 &gt;= to.length) { alert('Please enter a valid email address!'); return false; } if(to.length == 0) { alert('Please enter a valid email address!'); return false; } $.mobile.showPageLoadingMsg(); $.post('./services/service.email.php', { id: id, to: to, message: message}, function(data) { if(data.success == true) { $.mobile.hidePageLoadingMsg(); alert('Your recipe has been sent!'); $('#recipient').val(''); return true; } if(data.success == false) { if(data.fail == 1) { alert('An error has occured sending your recipe. Try again soon!'); return false; } if(data.fail == 2) { alert('Please enter a valid email address!'); } } }, 'json'); return false; }); </code></pre> <p>When you use event delegation you don't want to bind inside another event handler, because each time that event handler fires you will be re-binding (and when you delegate event handlers they are delegated for the life of the DOM).</p> <p>You can also use <code>.bind()</code> instead of <code>.live()</code> (this is my preferred method):</p> <pre><code>$( document ).delegate( "#page", "pageinit", function() { $('.eb').bind('click', ...); }); </code></pre> <p>You will notice that both of my examples change-out <code>.live()</code> for <code>.delegate()</code> as it performs slightly faster even when delegating from the <code>document</code> element. <code>.delegate()</code>s real strength is that you can choose the root element rather than having to bind to the <code>document</code> element: <a href="http://api.jquery.com/delegate" rel="noreferrer">http://api.jquery.com/delegate</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload