
jwplayer breaks .each loop?
If i get rid of jwplayer the .each loop works correctly, however with it in, the logs are incorrect. Is there a good way to loop through a dom like below to instantiate multiple jwplayers?
Any help would be great.
Regards
John
HTML ----
<div id=''
class="videoHeader"
data-video="/videos/video1.mp4"
data-image="/images/image1.jpg"
></div>
<div id=''
class="videoHeader"
data-video="/videos/video2.mp4"
data-image="/images/image2.jpg"
></div>
HTML END ----
JS ---
function init_video_headers($,jwplayer){
var headers = $(".videoHeader");
if(!headers.length){
return;
}
headers.each(function(i,d){
var el = $(d);
if(!el.hasClass('initiated')){
el.addClass('initiated');
var newid = "video-header-"+i;
el.attr('id',newid);
var videoUrl = el.attr("data-video"),
imgUrl = el.attr("data-image");
if(videoUrl){
console.log('id to input '+newid) // This outputs correctly if jwplayer is not included?
jwplayer(newid).setup({
file: videoUrl,
image: imgUrl,
skin : {
name:"helia"
}
}).on("ready", function(){
console.log("video ready");
});
}
}
});
}
JS END ---