# Javascript: changing background color

**URL:** <https://forum.kirupa.com/t/javascript-changing-background-color/27881>\
**Category:** Uncategorized\
**Created:** [August 7, 2003, 2:42pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881 "2003-08-07T14:42:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![blah\_de\_blah](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@blah\_de\_blah](https://forum.kirupa.com/u/blah_de_blah)\
**Post date:** [August 7, 2003, 2:42pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/1 "2003-08-07T14:42:42Z")

</div>

Ok so this is what i have to create (its from a tutorial) 🙂

[http://hotwired.lycos.com/webmonkey/98/03/homework3a/homework.html](http://hotwired.lycos.com/webmonkey/98/03/homework3a/homework.html)

But i can’t seem to get it to work? I tried view source but it doesn’t tell me the source for the other pages, only for the main page which holds all the sub-pages.

I have tried:

```php

<a href="#" onClick="top.frame2.document.body.bgcolor='red';">Red</a>

```

Shouldn’t that do the job for changing the background color to red? thanks!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 3:53pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/2 "2003-08-07T15:53:50Z")

</div>

```php

<A href="#" onclick="document.body.style.backgroundColor = '#ff0000';">red</a>

```

unless you want the page to automatically scroll back to the top i’d use ‘javascript: void(0);’ instead of ‘#’

btw for things like this i’d check msdn first: [http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods.asp](http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods.asp)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 4:09pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/3 "2003-08-07T16:09:55Z")

</div>

oh ok thanks, because the tutorial told me to do “#”, but i have no clue what it does 😛 Btw, don’t i need to target the frame i want the color to change in? so would it be:

frame2.document.body…

thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 6:11pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/4 "2003-08-07T18:11:31Z")

</div>

> \*Originally posted by blah-de-blah \*  
> \*\*oh ok thanks, because the tutorial told me to do “#”, but i have no clue what it does 😛 Btw, don’t i need to target the frame i want the color to change in? so would it be:

frame2.document.body…

thanks! \*\*

I’m pretty sure that’s the notation,

and btw in the previous post it says ‘about’, but it’s supposed to say: javascript

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 8, 2003, 4:22am UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/5 "2003-08-08T04:22:47Z")

</div>

ah yea its working, i just hadta add top.frame2 to the code, so i could target another frame. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 8, 2003, 4:26pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/6 "2003-08-08T16:26:56Z")

</div>

If you want the source then just right-click on the area where u think the frame is and say view source.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 8, 2003, 4:28pm UTC](https://forum.kirupa.com/t/javascript-changing-background-color/27881/7 "2003-08-08T16:28:46Z")

</div>

ahh thats how you do it, thx for the tip 😉
