function get_ads() { $.ajax({ url: "ads.html" }) .done(function(msg) { $("#ads .container").html(msg); }); } var check = document.getElementById("ads"); if(check != undefined) { get_ads(); }