jQuery/JavaScript: accessing contents of an iframe jQuery/JavaScript: accessing contents of an iframe javascript javascript

jQuery/JavaScript: accessing contents of an iframe


If the <iframe> is from the same domain, the elements are easily accessible as

$("#iFrame").contents().find("#someDiv").removeClass("hidden");

Reference


I think what you are doing is subject to the same origin policy. This should be the reason why you are getting permission denied type errors.


You could use .contents() method of jQuery.

The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page.

$(document).ready(function(){    $('#frameID').load(function(){        $('#frameID').contents().find('body').html('Hey, i`ve changed content of <body>! Yay!!!');    });});