1

I have to apply CSS to an <iframe> present in my HTML page using jQuery. The CSS must only be applied to that <iframe> and not the other parts of the HTML. Can anyone help me to do it using jQuery?

2 Answers 2

1

The best way to do it using just css is to access the iFrame with an id, like this:

$('#iframe-unique-name').children().css('background-color', 'red');

This would set the background color of the elements contained within the iframe to red, for example.

Sign up to request clarification or add additional context in comments.

Comments

1

If the iframe's URL (src attribute) don't violate the same domain policy, you should be able to...

$('iframe').contents().find('body').css({ fontSize: '130%' });

And if it doesn't, it will be on your domain. Can you just put the CSS there in the iframe's source?

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.