我已经动态附加了一个容器:
<video class="col-12 ml-auto col-12 mr-auto mp4Class" controls="controls">
<source src="${mp4ar} "type="video/mp4">
</video>
$('.container').append(card);
然后是一些条件
$(document).find(".mp4Class source").each(function(item, index) {
if (!this.src.includes('undefined')) {
console.log("src is:", item, index);
} else {
console.log("src is undefined:", item, index);
$(".mp4Class").hide()// hides all elements, not one
//$(this).hide() - doesnt work too
}
});
如果src
是undefined
,我需要隐藏一个元素-我该怎么做?
答案 0 :(得分:0)
我认为这是您需要的解决方案
$(document).find(".mp4Class source").each(function(item, index) {
var $this = $(item);
// if its not empty && doesn't contains the word undefined
if ($this.attr('src') && $this.attr('src') !== 'undefined'){
console.log("src is:", item, index);
} else {
console.log("src is undefined:", item, index);
$this.closest(".mp4Class").hide();
}
});