PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.info.authoring.CSS > Page background color won't change.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Page background color won't change.

Réponse
 
LinkBack Outils de la discussion
Vieux 19/03/2008, 14h38   #1
test9991014@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Page background color won't change.

Hi all,

I'm altering a page whose background color being set in CSS
somewhere. But I need to change the background color
in Javascript. I tried doing so with this:

document.bgcolor = "red";
alert(document.bgcolor);

When run, the value is apparently set because the alert displays
"red", however the page itself does not change color.

Anybody know what's going on?

Thanks.
  Réponse avec citation
Vieux 19/03/2008, 15h06   #2
Neredbojias
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.

On 19 Mar 2008, wrote:

> Hi all,
>
> I'm altering a page whose background color being set in CSS
> somewhere. But I need to change the background color
> in Javascript. I tried doing so with this:
>
> document.bgcolor = "red";
> alert(document.bgcolor);
>
> When run, the value is apparently set because the alert displays
> "red", however the page itself does not change color.
>
> Anybody know what's going on?


Yes, but it isn't you... "document.bgcolor" is SO wrong it flabbergasts
me! Google for "document.getElementById" and the css setting "background"
for further information.

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds
  Réponse avec citation
Vieux 19/03/2008, 15h36   #3
test9991014@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.


> Yes, but it isn't you... "document.bgcolor" is SO wrong it flabbergasts
> me! Google for "document.getElementById" and the css setting "background"
> for further information.


The body tag has no id, nor can I set one. However I did this

var foo = getelementbytagname("body")
foo.style.background = "red"

....and nothing changed.
  Réponse avec citation
Vieux 19/03/2008, 15h37   #4
test9991014@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.

Oops, I meant I did this

var foo = document.getelementbytagname("body")
foo.style.background = "red"

...and nothing changed.

  Réponse avec citation
Vieux 19/03/2008, 15h41   #5
test9991014@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.


This worked

var foo=document.getElementsByTagName("body")
foo[0].style.background="red"
  Réponse avec citation
Vieux 19/03/2008, 15h51   #6
Jukka K. Korpela
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.

Scripsit test9991014@yahoo.com:

> The body tag has no id, nor can I set one.


So whose document are you playing with, and why?

> var foo = getelementbytagname("body")
> foo.style.background = "red"


When everything else fails, read the ******* manual. In this case, start
from a primer on JavaScript, preferably a mordern one which is based on
W3C DOMs.

This is simple sample code, just to prove that you need to actually
study JavaScript before trying to use it:

var body = document.getElementsByTagName("body")[0];
body.style.backgroundColor = "red";

Note that JavaScript is case sensitive (and typically uses camelCase for
identifiers).

Beware that this code needs to be placed so that when it is executed,
the document, including the body element, has been loaded and parsed.

Followups trimmed. This is about JavaScript and DOM, not CSS, so both
group choices were wrong, but alt.html (a catchall group) is less wrong.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

  Réponse avec citation
Vieux 19/03/2008, 15h52   #7
Jonathan N. Little
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.

test9991014@yahoo.com wrote:
> This worked
>
> var foo=document.getElementsByTagName("body")
> foo[0].style.background="red"


Yes it s when you

a) use the correct function name, yes it is case sensitive
b) take note of the return value

It "works" if client has JavaScript enabled.


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
  Réponse avec citation
Vieux 19/03/2008, 16h08   #8
Harlan Messinger
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Page background color won't change.

test9991014@yahoo.com wrote:
> Hi all,
>
> I'm altering a page whose background color being set in CSS
> somewhere. But I need to change the background color in Javascript. I
> tried doing so with this:
>
> document.bgcolor = "red";


This doesn't alter any style. It doesn't do anything, in fact, other
than add a previously nonexistent field called "bgcolor" to the document
object and set its value to "red". Now, the BODY tag in transitional
HTML has an attribute called "bgcolor", but in Javascript, for whatever
reason, it's called document.bgColor, and names are case-sensitive in
Javascript.

Still, this has nothing to do with any properties that have been set
with CSS. A CSS property for an element is set in Javascript as follows:

var element = ...;
element.style.propertyName = "...";

The name of the CSS background color property in Javascript is
"backgroundColor".

> alert(document.bgcolor);
>
> When run, the value is apparently set because the alert displays
> "red", however the page itself does not change color.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h10.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12475 seconds with 16 queries