HTML
<div class="col-sm-4">
<div class="thumbnail">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/2tM1LFFxeKg" frameborder="0" allowfullscreen=""></iframe>
</div>
<div class="caption">
<p>Duration:
<span class="video-time">4:20</span>
</p>
<button type="button" class="btn btn-danger btn-block btn_video">
<strong>ADD</strong>
</button>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="thumbnail">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/2tM1LFFxeKg" frameborder="0" allowfullscreen=""></iframe>
</div>
<div class="caption">
<p>Duration:
<span class="video-time">4:20</span>
</p>
<button type="button" class="btn btn-danger btn-block btn_video">
<strong>ADD</strong>
</button>
</div>
</div>
</div>
BTN追加それぞれに
$('body').on('click', '.btn_video', function() {
var urls = [];
$('.btn_video').each(function() {
urls.push($(this).parent().parent().parent().find(".thumbnail").closest(".embed-responsive").html());
});
var str = '';
urls.forEach(function (url) {
str += url;
});
$('#usp-custom-5').val(str);
});
JSをクリックすると、アレイに全体iframe
を追加しようとしていますどのような私はouを印刷していますtは次のとおりです。
はこれについて
あなたが持っているDOMナビゲーションは間違っています。 '.closest()'を使って ".col-sm-4"コンテナを見つけ、 '.find()'を使って '
もし私がurls.push($(this)).parent()。parent()。parent()。find( "。thumbnail").html())を使用すると、私はiframeですべてのdivを取得します –