javascript document.getElementById in other frames

ante.sabo picture ante.sabo · Nov 27, 2009 · Viewed 56.8k times · Source

I have two frames and want to access an element in one frame from another:

Frame 1:

<div id='someId'>...</div>

Frame 2:

var div=document.getElementById('someId');

div.innerHTML='something'; 

This is somehow not functioning in Firefox so I want to be sure, can I access an element in another frame by its ID?

Answer

rahul picture rahul · Nov 27, 2009

You can refer the other frame by using

window.frames["framename"]

and then you can refer the element in the DOM by using

window.frames["framename"].document.getElementById ( "yourelementid" );