我正在尝试使用jQuery为模态弹出窗口选择最近的iframe。这里有很多窗口,我想选择最近的iframe。我希望最近的()工作,但没有运气。我正在使用此弹出窗口http://dinbror.dk/bpopup/
HTML
<div class="button">Hello</div>
<div class="modal-popup" style="display: none;">
<iframe src="https://www.youtube.com/embed/Bjj58nbAMK8"></iframe>
</div>
的jQuery
$(document).ready(function(){
$('.button').click(function(event) {
$('.modal-popup').bPopup({
followSpeed: 200,
speed: 200,
});
});
});
答案 0 :(得分:0)
要查找相关的iframe,您需要使用.next()
获取紧随其后的兄弟,然后使用.find()
定位iframe
,例如:
$('.button').click(function(event) {
var modal = $(this).next('.modal-popup');
var iframe = modal.find('iframe');
modal.bPopup({
followSpeed: 200,
speed: 200,
});
});