親ページでiframe内の要素をクリックした際に要素の情報を取得したい。
下記のように書いてみましたが、発火せず困っています。
ネット上にもいくつかありますが、どれもうまくいかず質問しました。
よろしくお願いいたします。
親ページ
<html> <head> <script type='text/javascript' src="js/jquery-2.1.4.min.js"></script> <script> //************************************************************************ //画像クリック //************************************************************************ $(window).load(function() { $("#phbox").contents().find(".img_set").on("click touchend", function(e) { e.preventDefault(); alert($(this).data('no')); }); }); </script> </head> <body> <iframe src="hoge.html" width="100%" height='100%' frameborder="0" id="phbox"></iframe> </body> </html>
子(hoge.html)
<html> <head> <script type='text/javascript' src="js/jquery-2.1.4.min.js"></script> </head> <body> <div class='img_set' data-no='1'>ボタン</div> <div class='img_set' data-no='2'>ボタン</div> <div class='img_set' data-no='3'>ボタン</div> <div class='img_set' data-no='4'>ボタン</div> </body> </html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/18 02:37
2019/01/18 02:40
2019/01/18 02:43
2019/01/18 02:47
2019/01/18 02:57