Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery one not firing per element
    primarykey
    data
    text
    <p>I have some HTML code which creates three jQuery icons:</p> <pre><code>&lt;span class="ui-icon ui-icon-circle-close one-click" data-customer-id="1"&gt;&lt;/span&gt; &lt;span class="ui-icon ui-icon-circle-close one-click" data-customer-id="2"&gt;&lt;/span&gt; &lt;span class="ui-icon ui-icon-circle-close one-click" data-customer-id="3"&gt;&lt;/span&gt; </code></pre> <p>And some JavaScript jQuery code which I want to fire once per icon that is clicked. It works fine when I use this:</p> <pre><code>$(".one-click").one("click", function() { alert(this.dataset.customerId) } ); </code></pre> <p>However, when I try to use one of my own functions it only fires for the first icon clicked. It never fires when another icon is clicked for the first time:</p> <pre><code>$(".one-click").one("click", function() { my_custom_function(this.dataset.customerId) } ); </code></pre> <p>It works fine for the first icon that is clicked, but does not fire for the other icons that are clicked. The jQuery documentation says that it should fire once per element per event type. What am I missing? <code>my_custom_function</code> should execute for each element clicked...</p> <p>Edit:</p> <p>I should elaborate about <code>my_custom_function</code>. It actually reloads the spans from the web server. Specifically, they're enclosed in a div:</p> <pre><code>&lt;div id="my_div"&gt; &lt;span class="ui-icon ui-icon-circle-close one-click" data-customer-id="1"&gt;&lt;/span&gt; &lt;span class="ui-icon ui-icon-circle-close one-click" data-customer-id="2"&gt;&lt;/span&gt; &lt;span class="ui-icon ui-icon-circle-close one-click" data-customer-id="3"&gt;&lt;/span&gt; &lt;/div&gt; </code></pre> <p>... and somewhere inside my_custom_function I reload using <code>$("#my_div").load("/some_url/")</code>. After commenting this load line out, the functions appear to be firing correctly. How can I apply the one-time-trigger functions after <code>load()</code>? Calling <code>one()</code> on the elements again doesn't seem to be doing the trick.</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.
 

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