Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define an event on iFrame element with jQuery

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 know how i can define the events for the iFrame, because I would like to put a thing like $('img').live("click",function().... but only for the elements on iFrame.

Please note: img tags are dynamically added on my iFrame after page load.

Thanks for your help.

Nicolas

like image 606
sanceray3 Avatar asked Jan 22 '23 14:01

sanceray3


1 Answers

You can do it if you

  1. make sure that the page in the iframe has its own copy of jQuery loaded [ed.: only really necessary for jQuery operations internal to the frame's page itself]
  2. from the outer document, work into the iframe document like this:

$('#iframeId').contents().find('img') // ...

like image 132
Pointy Avatar answered Feb 01 '23 03:02

Pointy