I have the following object which has been passed from PHP
var phpVars = {"embedCode0":"<iframe id="player_0"></iframe>",
"embedCode1":"<iframe id="player_1"></iframe>",
"embedCode2":"<iframe id="player_2"></iframe>",
};
My HTML contains a matching number of <div class="video-container"></div>
elements. I want to append each of the array items to each div in order. So that "embedCode0"
is appended to the first div, "embedCode1"
is appended to the second div and so on.
My jQuery function looks like this:
function vids(){
var $video = $('div.video-container');
$video.each(function(index) {
var $iframe = phpVars.embedCode + index;
$(this).append($iframe);
});
}
The function returns NaN. I have attempted to convert the index to a string but have not been able to succeed.
How can I increment the "embedCode"
string?