document.getElementById coming back with null for a known element - why? document.getElementById coming back with null for a known element - why? google-chrome google-chrome

document.getElementById coming back with null for a known element - why?


GMail is composed of frames. This one works:

frames[3].document.getElementById('gbx3');

In general, if you know the ID of the iframe element, the contentDocument property can be used (provided that you don't have same-origin problems, and the document is loaded):

document.getElementById('hist_frame').contentDocument.getElementById('gbx3');


As per my comment:

My best bet is that gbx is inside the iframe that contained the search result, and document.getElementById works on the same scope as your console

You can search all the frames to find what you need:

for(var i = 0; i < frames.length; i++) {   var curDoc = frames[i].document;   if(curDoc.getElementById('gbx')) console.log(curDoc.getElementById('gbx'));}