I'm running into a bit of an issue with this site I am currently building, I am using jQuery's .load() to grab an html file and include it in the #content of my site
<a href="#" onclick="$('#content').load('port/1.html')">1</a>
The chunk of code that is being pulled in has a jQuery click function on a few thumbnail images..
<div id="bigImg"><img src="images/1large.jpg" alt="Large View" id="lrg" /></div>
<div id="thumbCont">
<div class="thumb first"><img src="images/thumb1.jpg" alt="Thumbnail 1" data-lrg="images/1large.jpg" class="th"></div>
<div class="thumb"><img src="images/thumb2.jpg" alt="Thumbnail 2" data-lrg="images/2large.jpg" class="th"></div>
<div class="thumb"><img src="images/thumb3.jpg" alt="Thumbnail 3" data-lrg="images/3large.jpg" class="th"></div>
<div class="thumb"><img src="images/thumb4.jpg" alt="Thumbnail 5" data-lrg="images/4large.jpg" class="th"></div>
<div class="thumb last"><img src="images/thumb5.jpg" alt="Thumbnail 5" data-lrg="images/5large.jpg" class="th"></div>
</div>
and here is the jQuery to swap the images..
$(document).ready(function() {
$('img.th').click(function(){
lrg = $(this).attr('data-lrg');
olrg = $('#lrg');
if (lrg != olrg.attr('src')) {
olrg.fadeOut('normal',function(){olrg.attr('src',lrg)});
olrg.fadeIn();
}
});
});
So when the user clicks on the image, jquery pulls the new image src from data-lrg. This function works great, until I decided to pull the html with jquery instead of php.
Any idea why jQuery would not recognize the new html?
My thoughts: I'm guessing it has something to do with jQuery setting up shop before this part of the page is loaded, which tells me that I need to figure out a way to tell jQuery to look at this section again, or look at the whole page again.... but I am at a loss on how to do that.
(I know the onclick isn't the best way to do it, but it makes it easy for early development)