I have a function that I want to return HTML and then use it in a conditional if statement in a wider function.
function adverts(selector, dfp, index, tempURL) {
$(dfp).each(function(){
var code = $(this).data("dfpcode");
var position = $(this).data("adposition");
if(index == position) {
$.get(tempURL + "/shortcodes.php?shortcode=" + code, function() {
}).done(function(content){
return content;
});
}
else {
return "";
}
});
}
And I want to use it here
var dfpHTML = adverts(selector, ".dfp", i, tempURL).parseHTML();
if(dfpHTML.length > 0) {
$(div).append(dfpHTML);
}
else {
}
but when I run this in my function this is the error I get
TypeError: adverts(...) is undefined