Accessing DOM element of child IFRAME in same domain

metalaureate used Ask the Experts™
I'm trying to access a child element inside an IFRAME, all same domain. How do I do that? The element has an ID. I'm blanking out on this one.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Use : document.getElementById("myframeID").contentWindow.document
for just javascript this should get you going..

var iframe = document.getElementsByTagName('iframe')[0],
    iDoc = iframe.contentWindow     // sometimes glamorous naming of variable
        || iframe.contentDocument;  // makes your code working :)
if (iDoc.document) {
    iDoc = iDoc.document;
    iDoc.body.addEventListener('afterLayout', function(){

but if you have jQuery loaded..

            $('#frame_SIA').ready(function() {
                  var x=document.getElementById("frame_SIA");
                  var y=(x.contentWindow || x.contentDocument);
                  $(y.document).bind('keydown', 'ctrl+s', function(evt) {
                        alert('got there');

which is way better... Cheers -Jeremy


Thanks guys. I can't close this question - something is jacked with EE, doesn't let me Accept answers.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial