daniel.tosaba daniel.tosaba - 8 months ago 35
HTML Question

jquery load() after ajax page is loaded - howto

i have following lines included at the bottom of my index.php:

<script type="text/javascript" language="javascript" src="class/jquery-1.4.3.min.js"> </script>
<script type="text/javascript" language="javascript" src="class/jquery.nivo.slider.pack.js"></script>
<script type='text/javascript' language='javascript'>
$(window).load(function() {

problem lies in

index.php's body is updated onload through ajax call which delivers div#slider upon matching. this makes it
not executing. do you have any trick to make this thing work. i do prefer non-jquery way around it, but at the end of the day anything helps.

many thanks



Add the call in the callback for the AJAX load.

$('.something').load( 'http://www.example.com/foo', function() {

Example using your code (for body):

$(function() { // run on document ready, not window load
     $('#content').load( 'page.php?c=2&limit=5', function() {

For link:

<!-- updates links like so -->
<a class='nav' href='page.php?category=art&limit=5&c=1'>art</a>

// in the same document ready function
     $('a.nav').click( function() {
          var $link = $(this);
          $('#content').load( $link.attr('href'), function() {
               $link.addClass('selected'); // instead of setting bg directly to #828282;
          return false; // to prevent normal link behavior