How to Invoke JS Within an iFrame

If you need to access HTML elements or Javascript code within an iFrame, here’s how to do it:

var cw = document.getElementById('theIFrameID').contentWindow;
cw.document.body.style.backgroundColor = '#f00'

Have jQuery in the iFrame? You can access it this way:

alert(cw.$('body').html());