ssahu
ssahu

Reputation: 888

Adding CSS to an <iframe>

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?

Upvotes: 1

Views: 513

Answers (2)

squeezemylime
squeezemylime

Reputation: 2102

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.

Upvotes: 1

alex
alex

Reputation: 490233

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?

Upvotes: 1

Related Questions