What is JavaScript equivalent to jQuery.contents ()?

I want to change the class property to an iframe, I use .contents()one that works fine. But I want to do this using JavaScript. My code is:

var $c = $('#myframe').contents();              
$c.find('.inner-wp').css('margin','0')
+5
source share
1 answer

.contents()in the frame returns the document inside the frame. So you are looking for:

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

Note. This will not work if the frame has a different origin.
The rest 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';
}
+8
source

All Articles