2016-12-14 3 views
0

私のページに2つのiframeがあるiframe-menuiframe-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を非表示にしたいと考えています。

+2

の可能性のある重複した[jQueryのをJSFiddleをチェック.hide()

$('body').click(function(event) { if (!$(event.target).hasClass('.options')) { $(".test").contents().find(".options").hide(); } }); 

はIFRAME &のクラス名を設定してみてください使用.content().find()

を使用して要素を非表示にすることですdivを除いてすべてをクリックすると、その子どもたち](http://stackoverflow.com/questions/12690) 313/jquery-on-click-on-a-div-and-its-children) – Roberrrt

答えて

0

ベストな方法は、

JSFiddle

+0

あなたのコードはメインページ要素の隠蔽のために働き、iframe内の要素を隠したいと思っています。 –

+0

私の答えを編集しました! – Andy

関連する問題