1

I've got this piece of HTML:

<html>
  ...
  <iframe>
    #document
    <html>
      ...
      <div className='change-me'></div>
      ...
    </html>
  </iframe>
</html>

That iframe is taken from stripe React element, I want to access something inside it and change its CSS.

I've dealt before with libraries that offer reusable React components, and managed easily to change every CSS detail there.

Problem: But here I can change nothing.

.change-me { background: red } // This one doesn't work 

Maybe it's the fact that the component is making it's own html document, maybe I'm looking at the problem from the wrong end...

1
  • 1
    if it's an iframe than you cannot Commented Oct 17, 2018 at 10:36

1 Answer 1

1

Plain CSS is not going to work. You need to change the class of the element with your own class programmatically using JavaScript and the iFrame must contain the CSS file/styling containing that class

For example, you can add your CSS file to the iframe like this:

var iFrame = document.getElementById("youriFrameId");
var head = iFrame.getElementsByTagName("head")[0];

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'path/to/cssFile.css';

head.appendChild(link);

and then add your class to your target element like this:

iFrame.getElementById('targetElementId').classList.add("yourClass");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.