Element doesn't exist

I know this issue is because of the map-points element not existing yet, so when I try and add a class to it…it doesn’t exist.

$('.map-container').each(function () {
      // add container to clone points for map. 
      $('<ul class="map-points"></ul>').appendTo( $(this).find('.fsElementContent') );
    });
    $('.map-key').each(function () {
      // add css class to each location
      $(this).find('.fsNavLevel1 > li').each(function(i) {
        $(this).addClass('pin-' + (i+1));
        $(this).find('a').wrapInner('<span class="map-text"></span>');
        $(this).clone().appendTo('.map-container .map-points');
      });
      // When a map point is clicked, load up the slideshow, and activate the slider that appears
      $('.campus-map .map-container').append('<div class="map-pop-wrapper"><div class="map-pop-container"></div></div>');
      $(this).find('a').click(function(){
        var pinIndex=$(this).parent().index() + 1;
        console.log(pinIndex);
        console.log($(".map-points .fsNavLevel1 li.pin-"+pinIndex).length);
......

How can I work around this? The .click() anchor is in a separate part of the page.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.