隐藏类中的一个元素

时间:2018-07-24 14:56:45

标签: jquery ajax

我已经动态附加了一个容器:

<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
  }
});

如果srcundefined,我需要隐藏一个元素-我该怎么做?

1 个答案:

答案 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();
  }
});

相关问题