Owais Ahmed
Owais Ahmed

Reputation: 1438

Changing body bgcolor inside iframe

I want to change the Body bgcolor inside iframe. This is my iframe

  console.log(iframe)

image

I used this code

$(iframe.id).contents().find('body').css({'background-color' : 'transparent'});

it is adding transparent inside the style but i want to change bgcolor:#ffffff to transparent. See the attached image below.

image2

Upvotes: 0

Views: 1592

Answers (1)

Ɛɔıs3
Ɛɔıs3

Reputation: 7853

You may just doing this :

$('iframe').contents().find('body').css({'background-color' : 'transparent'});

If it doesn't work, try that :

$('iframe').contents().find('body').css({'background-color' : 'inherit'});

$('iframe').contents() gets the content of the iframe, then you can change the backgroud of the body

EDIT :

So, following the comments, to remove the bgcolor attribute and add the transparent background, do that :

$('iframe').contents().find('body').css({'background-color' : 'transparent'}).removeAttr('bgcolor');

Upvotes: 3

Related Questions