Mar 25, 2010 #1 bazil2 Technical User Joined Feb 15, 2010 Messages 148 Location DE (Elementary user) Is it possible to define a variable in JavaScript to represent a web colour, like this? ... var bgcolor = "'FF0033" ...
(Elementary user) Is it possible to define a variable in JavaScript to represent a web colour, like this? ... var bgcolor = "'FF0033" ...
Mar 25, 2010 1 #2 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO 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. http://free.rootshell.be/~feherke/ Upvote 0 Downvote
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. http://free.rootshell.be/~feherke/