@wilmer.lemke
To change the body CSS elements inside an iframe, you can use the following steps:
1 2 |
const iframe = document.querySelector('iframe');
const iframeDocument = iframe.contentWindow.document;
|
For example, you can change the background color of the body inside the iframe:
1
|
iframeDocument.querySelector('body').style.backgroundColor = 'red';
|
1 2 3 4 5 |
// Add a class to the body element
iframeDocument.querySelector('body').classList.add('new-class');
// Apply inline styles to the body element
iframeDocument.querySelector('body').style.fontSize = '24px';
|
By following these steps, you can change body CSS elements inside an iframe using JavaScript.