Define an event on iFrame element with jQuery

后端 未结 6 2052
Happy的楠姐
Happy的楠姐 2020-12-18 09:19

I try to define a live event on img tags store on a iFrame. For example, I would like obtain a simple javascript alert box when I click a image on my iFrame.

Do you

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 09:51

    this worked for me. NB: make sure you have referenced jquery library on the iframe page as well.

    $(document).ready(function(){
        $('#iframeid').load(function(){ //make sure that all elements finish loading
                $('#iframeid').contents().find('img').live({
                     click: function(){
                        alert('clicked img');
                     }
                });
            });
        });
    

提交回复
热议问题