Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defining a variable in JS to represent a colour - is it possible? 1

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
DE
(Elementary user)

Is it possible to define a variable in JavaScript to represent a web colour, like this?

...
var bgcolor = "'FF0033"
...
 
Hi

Let us see...
Code:
[blue]>>> typeof document.body.style.color[/blue]
[red]"string"[/red]
So colors are stored as strings. So, yes, you can store colors as strings in JavaScript variables.

But note that 'FF0033 is not a valid color. Hexadecimal color codes have to be prefixed with a hash ( # ) sign :
JavaScript:
[b]var[/b] bgcolor     [teal]=[/teal] [green][i]"[highlight]#[/highlight]FF0033"[/i][/green]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top