0

I want to call a variable, which stores some html markup with some data, when my URL contains a specific string. The data is accesible after a timeout function I made, and the console spits out the correct markup.

var mapData = setTimeout(function() {
    var mapContent = $('.case__map').html(); // THIS DATA I WANT
},3000)

if (window.location.search == '?print=1') {
   $('.presentation-list').find('[data-type="image"]').each(function () {
      var src = $(this).attr('data-src');
      $('.newData').append('<div><img src="' + src+ '"/></div>')
  });
  // HERE I WANT TO APPEND THE DATA INSIDE "MAPCONTENT" TO A NEW DIV
  // HOW TO ACHIEVE THIS?      
}

any help is appreciated

ST80
  • 3,565
  • 16
  • 64
  • 124

1 Answers1

1

You can wrap an action you want to do after the timeout in a function and call it in the timeout function.

var mapData = setTimeout(function() {
    var mapContent = $('.case__map').html(); // THIS DATA I WANT
    appendData(mapContent);
},3000)

if (window.location.search == '?print=1') {
   $('.presentation-list').find('[data-type="image"]').each(function () {
      var src = $(this).attr('data-src');
      $('.newData').append('<div><img src="' + src+ '"/></div>')
  });    
}

function appendData(data) {
    if (window.location.search == '?print=1') {
       // append data where you want.
      // HERE I WANT TO APPEND THE DATA INSIDE "MAPCONTENT" TO A NEW DIV
      // HOW TO ACHIEVE THIS?      
    }
}
Stepashka
  • 2,648
  • 20
  • 23