href - Init js after Ajax call -
i have small javascript used swap images using href links. ok except when call ref inside page using ajax. need find way initialize again script after calling new links. here js:
<script type="text/javascript"> $('a.thumbnail').click(function(){ var src = $(this).attr('href');
if (src != $('img#largeimg').attr('src').replace(/\?(.*)/,'')){ $('img#largeimg').stop().animate({ opacity: '0' }, function(){ $(this).attr('src', src+'?'+math.floor(math.random()*(10*100))); }).load(function(){ $(this).stop().animate({ opacity: '1' }); }); } return false; });
thank you
you need delegate events.
turn this:
$('a.thumbnail').click(function(){ /*...*/ }); into this:
$('#somewrappercontainer').on('click', 'a.thumbnail', function(){ /*...*/ }); make sure you're using jquery 1.7+
Comments
Post a Comment