I'm trying to fire a click event on the click of an element inside an iframe, but it doesn't seem to be working. My current set up:
jsFiddle: http://jsfiddle.net/q4aa3/
jQuery:
$(document).ready(function () {
$('#this-iframe').load(function () {
$('#this-iframe').contents().find('img').live({
click: function () {
alert('clicked img');
}
});
});
});
Clicking on the image inside the iframe isn't firing the alert, I'm not sure why, or is there a better way to achieve this? Any suggestions would be greatly appreciated!
fiddle.jshell.netand your iframe is loadingjsfiddle.netwhich means they are different domains so you do not have access to it. Also jQuery's.loadfunction loads in data from a url, it is not a onload event. jQuery load docs.load()is also used to handle the load event: api.jquery.com/load-event