Re-initialise jquery on ajax loaded content

Re-initialise jquery on ajax loaded content

Hi, I am loading a gallery dynamically using ajax. I know i need to re-initialise the photoswipe lightbox after the ajax content is loaded. I am new to combining these things. If anyone can help with how to re-initialise the photoswipe jquery when the ajax content is loaded that would be great.
Thanks in advance
Richard

  1. $(function() {
  2. //More Button
  3. $('.more').live("click",function() 
  4. {
  5. var ID = $(this).attr("id");
  6. if(ID)
  7. {
  8. $("#more"+ID).html('<img src="moreajax.gif" />');
  9. $.ajax({
  10. type: "POST",
  11. url: "Ajax_more_demo.asp",
  12. data: "lastmsg="+ ID, 
  13. cache: false,
  14. success: function(html){
  15. $("ul#Gallery").append(html);
  16. $("#more"+ID).remove();
  17. }
  18. });
  19. }
  20. else
  21. {
  22. $(".morebox").html('The End');
  23. }
  24. return false;
  25. });
  26. });


  1. (function(window, PhotoSwipe){
  2. document.addEventListener('DOMContentLoaded', function(){
  3. var
  4. options =  {
  5. getImageMetaData: function(el){
  6. return {
  7. relatedUrl: el.getAttribute('data-related-url')
  8. }
  9. }
  10. },
  11. instance = PhotoSwipe.attach( window.document.querySelectorAll('#Gallery a'), options );
  12. instance.addEventHandler(PhotoSwipe.EventTypes.onTouch, function(e){
  13. if (e.action === 'tap'){
  14. var currentImage = instance.getCurrentImage();
  15. window.open(currentImage.metaData.relatedUrl);
  16. }
  17. });
  18. }, false);
  19. }(window, window.Code.PhotoSwipe));