Note that there are some explanatory texts on larger screens.

plurals
  1. POClick event handler for dynamically-generated input/button?
    text
    copied!<p>Can I use exactly the same code to handle clicks for static and for Ajax-generated buttons? The reason I ask is that I can't get a click handler to work for an Ajax button, but if I write the equivalent static HTML, the click does work.</p> <p>This code is the static version, which does work:</p> <pre><code>// in JS file: $(function(){ $('input.sButton').click(function(){ var f = $.farbtastic('#picker'); f.linkTo(this); return false; }); }); </code></pre> <p>In the "static HTML":</p> <pre><code>&lt;div id = "inputArea"&gt; &lt;label style="white-space: nowrap; line-height: 14px; height: 14px; vertical-align: bottom;"&gt; &lt;input id="sButton1" class="sButton" type="button" style="background-color: rgb(113, 16, 232);"&gt; fubar1 &lt;/label&gt; &lt;/div&gt; </code></pre> <p>The normal "dynamic HTML" looks like this:</p> <pre><code>&lt;div id = "inputArea"&gt; &lt;/div&gt; </code></pre> <p>The Ajax code loads the buttons into 'inputArea'. I derived the static version of this code from Firebug. I ran the Ajax routine, then got the HTML view in Firebug, which included the server output, and cut-and-pasted it exactly into my static test code, which is reproduced above. In other words, I know that the static and dynamic HTML are equivalent.</p> <p>But - the static code works, and the dynamic one doesn't. Firebug shows the JS click handler being entered for the static version, and the farbtastic colour picker pops up, but this doesn't happen in the dynamic code. Any ideas?</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