javascriptdomhtml-frames

javascript document.getElementById in other frames


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?


Solution

  • 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" );