Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking jquery .on function work with AJAX loaded content
    text
    copied!<p>I am having trouble getting an .on 'click' function to work upon AJAX loaded content.</p> <p>I have worked with the jquery .live before but this is the first time with .on and understand it works in the exact same way so unsure why I am having problems.</p> <p>Below is the HTML that gives the element to which you click on</p> <pre><code> &lt;h1&gt;Press &amp;amp; Media&lt;/h1&gt; &lt;div id="back"&gt;&lt;/div&gt; &lt;div id="overlay-content"&gt; &lt;span id="edocs" class="tab"&gt;&lt;/span&gt; &lt;span id="news" class="tab"&gt;&lt;/span&gt; &lt;span id="partners" class="tab"&gt;&lt;/span&gt; &lt;/div&gt; </code></pre> <p>Below is the function that loads the AJAX content.</p> <pre><code> $("#overlay-content").on('click','#news',function() { var active = 1; $("#loading").show(); $("#overlay-content").fadeOut(1000, function() { $.get("http://&lt;? echo ROOT; ?&gt;includes/functions.php", { pressmediaNews: active }, function(data) { $("#loading").hide(400); $("#overlay-content").empty().append(data).fadeIn(1000); }); }); }); </code></pre> <p>This should load the following HTML</p> <pre><code> &lt;div id="news-left-panel"&gt; &lt;h4&gt;News Section&lt;/h4&gt; &lt;ul&gt; &lt;li id="newsID2" class="newsYear"&gt; &lt;p&gt;2012&lt;/p&gt; &lt;ul class="newsMonths" style="display:none"&gt; &lt;li&gt;Jan &lt;ul class="newsArticles" style="display:none"&gt; &lt;li onClick="newsID(2)"&gt;test&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;Feb&lt;/li&gt; &lt;li&gt;Mar&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="newsID1" class="newsYear"&gt; &lt;p&gt;2011&lt;/p&gt; &lt;ul class="newsMonths" style="display:none"&gt; &lt;li&gt;Dec &lt;ul class="newsArticles" style="display:none"&gt; &lt;li onClick="newsID(1)"&gt;Test&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Now the above code simply wont execute, show any errors etcetera in firebug.</p> <p>So I'm a bit lost as to why it wont execute, the alert() even does not execute.</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