Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't call javascript from ajax div
    primarykey
    data
    text
    <p>I have some content loaded in my page using ajax. I want to run a JS function when some anchors are clicked. These anchors belongs to the code loaded using ajax. Both the ajax request and the JS function are located in a separate JS file, inside a <code>jQuery(document).ready(function() {</code>.</p> <p>I have a few dozens functions in this JS file, and they're running fine, but this specific function is the only one called by code retrieved using ajax, and it is not working. My code:</p> <p><strong>html main file:</strong></p> <pre><code>&lt;!-- code --&gt; &lt;div id="ajaxContentGoesHere"&gt; &lt;!-- content inserted here by ajax function --&gt; &lt;td&gt;&lt;a href="#" id="aLancamentoEdit&lt;?php echo $lancamento['Lancamento']['lan_itid']; ?&gt;"&gt;Editar&lt;/a&gt;&lt;/td&gt; &lt;/div&gt; &lt;script src="/js/myJS.js"&gt;&lt;/script&gt; &lt;/body&gt; </code></pre> <p><strong>/js/myJS.js file:</strong></p> <pre><code>jQuery(document).ready(function() { /*some other functions here*/ $("[id^='aLancamentoEdit']").click(function(){ console.log(1); } }); </code></pre> <p>I tried to put the <code>$("[id^='aLancamentoEdit']").click(function(){</code> inside the html main file, in a tag after the <code>/js/myJS.js</code> call. Didn't work. Also tried to change the selector to match my anchor class (I declared a class for this). No success either. Finally tried also to put a name in the function and call it on <code>onclick=""</code> inside the anchor. Failed again.</p> <p>What am I doing wrong?</p>
    singulars
    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