What is the JavaScript equivalent to jQuery's .contents()?

javascript, jquery

Solution

`.contents()` on a frame returns the document within the frame. So, you're looking for:

var frame = document.getElementById('myframe');
var c = frame.contentDocument || frame.contentWindow.document;

Note: This won't work if the frame is from a different origin. The remaining part of the code:

var inner_wp = c.getElementsByClassName('inner-wp');
for (var i=0; i<inner_wp.length; i++) {
    inner_wp[i].style.margin = '0';
}

Problem

I want change class property on an iframe I use `.contents()` which is perfectly working. But I want to do this using JavaScript. My code is: ``` var $c = $('#myframe').contents(); $c.find('.inner-wp').css('margin','0') ```

Original source