Page 1 of 1

jQuery not working on ajax pages

Posted: Thu Aug 21, 2008 2:32 pm
by GeXus
I've had this problem before but never found a solution, so here's goes..

I have some pages that are loaded via ajax... basically, a page is being loaded into a div. I want the content within that div (or the remote page) to use jQuery. the document.ready does not work, neither do any other functions.

Any idea how to do this?

Also to note, I have jQuery being included in both the remote page and the parent.

Thanks!

Re: jQuery not working on ajax pages

Posted: Thu Aug 21, 2008 3:55 pm
by lukewilkins
I personally prefer Prototype: http://www.prototypejs.org/ :wink:

BUT, jQuery will work the same way in which once a div is loaded with content (via Ajax) it is "part" of the parent page. Meaning, it can access all of the functions present on that page including those part of jQuery.

If you don't understand what I'm saying, leave your code here and I'll take a look at it for you.

Luke

Re: jQuery not working on ajax pages

Posted: Thu Aug 21, 2008 6:17 pm
by GeXus
Ahhh.. I see... However, it still doesn't seem to work.. I must be doing something wrong..


Here's snippets of the code

Main Index (Parent)

Code: Select all

 
$(document).ready(function(){
$('#delete').click(function(){
        alert('test');
    });
});
 
Ajax Page being loaded into <div id="content"></div> from parent.

Code: Select all

 
<a href="#" id="delete">delete</a>
 
I put this in as a test and it didn't work...

Re: jQuery not working on ajax pages

Posted: Thu Aug 21, 2008 6:39 pm
by GeXus
I got it.. I was calling it before the ajax was executed... Thanks so much!!! Seems very simple, but literally spent hours trying to figure it out.. thanks!

Re: jQuery not working on ajax pages

Posted: Thu Aug 21, 2008 8:18 pm
by lukewilkins
No problem. Glad it is working for you!

Luke