私のページに2つのiframeがあるiframe-menuとiframe-content。 私は非表示にするiframe-content要素( '.options')は、ページ全体、つまり.options divの外にある任意のクリックイベントに適用されます。Jquery - メインページの本文でiframeコンテンツを非表示にする
メインページ:はiframeコンテンツで
<body>
<iframe src="menu.html" id="iframe-menu" height="100%"></iframe>
<iframe src="content.html" id="iframe-content" height="100%"></iframe>
</body>
content.html
<div class="container">
<div class="options">Hello</div>
</div>
私はjqueryのコードを使用しています。しかし、現在のiframeをクリックしたときにのみ動作します。
$(document.body).click(function(event) {
var target = $(event.target);
if (!target.parents().andSelf().is('.options')) {
$('.options').hide();
}
});
メインページをどこでもクリックしてdiv.optionsを非表示にしたいと考えています。
の可能性のある重複した[jQueryのをJSFiddleをチェック
.hide()
はIFRAME &のクラス名を設定してみてください使用
.content().find()
を使用して要素を非表示にすることですdivを除いてすべてをクリックすると、その子どもたち](http://stackoverflow.com/questions/12690) 313/jquery-on-click-on-a-div-and-its-children) – Roberrrt