Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call JQuery functions after page is loaded?
    text
    copied!<p>I have a page that has a button. When the button is pressed an AJAX call is made and then the html from that call replaces a div container I have on the main page. I have scripts that need to be loaded on the second page. So my concern is that when the scripts from the second page are running, it gives me a " Object # has no method 'find' " error in the console. Which I know that this is an issue of the script not being able to call the JQuery functions. Does anyone know how I can call the JQuery functions after a second page is generated? Here is an example as to what my page does:</p> <p>MAIN PAGE: </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; $(document).ready({ $('body').on('click', '.button', function() { $.ajax({ type: 'GET', url: 'page.php' data { ... }, success: function(e){ $('#container').html(e); } }); }); }); &lt;/script&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button class="button" value="Click me!"&gt;&lt;/button&gt; &lt;div id="container"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>PAGE.PHP:</p> <pre><code>echo '&lt;div id="dropbox"&gt;'; echo ' &lt;div class="message"&gt;Drop files here&lt;/i&gt;&lt;/div&gt;'; echo '&lt;/div&gt;'; echo '&lt;script src="js/filedrop.js"&gt;&lt;/script&gt;'; echo '&lt;script src="js/upload.js"&gt;&lt;/script&gt;'; </code></pre> <p>And then when the scripts are executed from the second page I get the &lt; Object # has no method 'find' > error. If I include the scripts on the main page, nothing works in the scripts. Anyone know where to point me in the right direction for all of this to work?</p> <p>EDIT **</p> <p>Sorry to confuse you guys. The code I put was just something that I had put together real quick. The button click code would be in the document.ready, but the other functions that are called from the second scripts are not in a document.ready. Do they need to be in a document.ready callback for them to recognize the JQuery functions?</p> <p>EDIT 2 **</p> <p>Thanks for clarifying that you can have more than one Document.Readys. I will be selecting the answers after the 10 minute window is up.</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