我想调用一个函数,当我点击一个iframe时,我的解决方案在jQuery上工作得很好,但是当触发函数时我需要回到包含iframe的元素。
$('#window-3 iframe').load(function () {
$(this).contents().find("body").click(function () {
// Here I need to select the iframe again
});
});
答案 0 :(得分:1)
在这种情况下,您需要$(this).parent()
。如果要选择具有特定类的父级,则可以使用$(this).parents('#window-3')
。
您可能还想澄清任何潜在的范围问题:
$('#window-3 iframe').load(function () {
var _me = $(this);
_me.contents().find("body").click(function () {
var _parent = _me.parent()
// Here I need to select the iframe again
});
});