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

2
  • If the content is in a asynchronous call, you can not do what you want to do... Commented Dec 8, 2015 at 13:12
  • I think this may help you to put MAP stackoverflow.com/questions/34130565/… Commented Dec 8, 2015 at 13:13

1 Answer 1

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?      
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! This was exactly what I needed! :-)
Can we agree that its $('.newData').append('<div>' + data + '</div>'); ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.