# \[JavaScript\] Possible to change CSS styles in an iframe?

**URL:** <https://forum.kirupa.com/t/javascript-possible-to-change-css-styles-in-an-iframe/167416>\
**Category:** web dev\
**Created:** [October 28, 2005, 12:08am UTC](https://forum.kirupa.com/t/javascript-possible-to-change-css-styles-in-an-iframe/167416 "2005-10-28T00:08:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MTsoul](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@MTsoul](https://forum.kirupa.com/u/MTsoul)\
**Post date:** [October 28, 2005, 12:08am UTC](https://forum.kirupa.com/t/javascript-possible-to-change-css-styles-in-an-iframe/167416/1 "2005-10-28T00:08:35Z")

</div>

Hey all,

I’m really troubled by this right now. **Is it possible to change CSS styles in an iframe on a page with Javascript from the main page?**

What this means is I can’t edit the iframe, and I will only have access to the source of the main page.

I got it to work with a link, as follows:

```auto
<a onClick="frames.my_iframe.document.getElementById('myId').style.color = '#000000'; return false" href="#">change the iframe</a>

```

However, this does not work if I simply insert “frames.my\_iframe.document.getElementById(‘myId’).style.color = ‘#000000’;” into a Javascript block. Why is this so?

Thanks in advance!

//edit. YES I’VE FIGURED IT OUT.
