Changing Style on Elements by ID

They have: 5,633 posts

Joined: Jan 1970

I have this problem. I don't know if this is the right area but here goes.

I have a color configuration setup that I want my clients to be able to manage. If it were personal style sheets it would be no problem.

What I want is the user to select colors from a color picker that I developed (that part works great). It sets the value in a text field with a hex number.

What I want to be able to do is have them select there colors and then see those colors on a little table that is a small version of the website.

So in essence I want to know how to get to work the ability to 'change styles' given particular ID with a click of the button.

I realize it will be a function and an onclick event, but can't get it to work.

The style changes are font colors, and bgcolors for 's as well as 's and even on a

Any Ideas I would greatly appreciate it.

Thanks,

Mired in microsoft....

He has: 1,380 posts

Joined: Feb 2002

you're going to need to use, assuming you have your font tags labeled id="font"

document.getElementbyId("font").style = (color: #000000;);
'

You need to implement something like that in your script

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

I've not encountered the syntax Kyle suggested. I believe this will work too:

document.getElementById("font").style.color = strColor;
'
where strColor has the value of the colour you're passing on from the picker.

Each style attribute has an equivalent identifier in script; color is color, background-color is backgroundColor, and so on. Only, I'm not sure if it is valid and whatnot. Might be worth some googling. Smiling

He has: 1,380 posts

Joined: Feb 2002

Yeah, my bad. I don't know what I was thinking...lol.

I even use something like this on one of my sites...wow.

Thanks Abhi.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.