I have several variables in my code :
var titre = bloc_movie_parent.attr("titre"),
director = bloc_movie_parent.attr("director"),
prod = bloc_movie_parent.attr("prod"),
agency = bloc_movie_parent.attr("agency");
using this variables i'm building a div using a for each function, and inside this div I have spans that should show but only if the variable exists.
here is my code :
$(".bloc_movie[type='"+ type + "']").each(function(){
var titre = $(this).attr("titre"),
director = $(this).attr("director"),
prod = $(this).attr("prod"),
agency = $(this).attr("agency"),
hash = $(this).children('a').attr("href");
$(".caption_slideshow").append('<div class="bloc_movie"><div class="legende"><div class="titre_caption">'+ titre +'</div><div><span class="initial_director">D/ </span>'+ director +'</div><div><span class="initial_prod">P/ </span>'+ prod +'</div><div><span class="initial_agency">A/ </span>'+ agency +'</div></div></div>');});
it works fine.
but sometimes my variable is empty. And when the variable is empty, I want the span to be hidden. for example if "director" is empty, I want the "initial_director" span to be hidden. same for "prod" with "initial_prod" span & "agency" with "initial_agency".
I can't find a way of doing it inside the append function.
can anybody help me with this ?