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')
.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';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With