function add_images(){ var el = document.getElementById("id_body_markdown"); var iframe = ''; el.insertAdjacentHTML('afterend', iframe); var featured_image = document.getElementById("id_featured_image") if (featured_image) { featured_image.querySelectorAll('li').forEach(function(element) { var cur = element.dataset.imageid if (cur != "") { var request = new XMLHttpRequest(); request.open('GET', '/photos/luximage/data/admin/tn/'+cur+'/', true); request.onload = function() { if (request.status >= 200 && request.status < 400) { var data = JSON.parse(request.responseText); var el = element.getElementsByTagName('label')[0]; url = "url('"+data['url']+"');"; //console.log(url); el.style.backgroundImage = 'url('+data["url"]+')'; //console.log(el.style); } else { console.log("server error", request.statusText); } }; request.onerror = function() { console.log("error on request"); }; request.send(); } }); } } document.addEventListener("DOMContentLoaded", function(event) { add_images(); });