Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The only explanation that fits the facts you've presented is that there is code running after your <code>ready</code> callback but before you click the element that <em>replaces</em> the element in question. Some kind of ajax callback or similar.</p> <p>You'll need to look through your code to find the place where that's happening. Things to look for are any <code>html</code> calls on elements that contain the <code>#label_19</code> element, or (if there's a mix of jQuery and non-jQuery code) assignments to <code>innerHTML</code>.</p> <p>You can use event delegation to solve this, which may or may not be the best answer depending on what your code is doing. That looks like this:</p> <pre><code>var j = jQuery.noConflict(); j(document).ready(function(){ console.log(j("#label_19")); j(document).on("click", "#label_19", function(){ // This is the changed line alert("Clicked"); }); }); </code></pre> <p>There, instead of hooking <code>click</code> on the actual element, we're hooking it on <code>document</code> but then asking jQuery to only tell us about clicks that pass through elements matching the selector we give it as they bubble. That way, the fact that something is destroying and recreating the <code>#label_19</code> element doesn't matter, because we're not hooking a handler on that element. We're hooking the handler on <code>document</code> and checking, when the event occurs, if it passed through something that matches that selector.</p> <p>But I wouldn't just blindly use event delegation, I'd find out what's really happening with that element.</p>
 

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