Forum Moderators: open

Message Too Old, No Replies

JavaScript to manipulate styles

         

jaytee

9:53 am on Jun 13, 2007 (gmt 0)

10+ Year Member



I am using JavaScript to change styles in a document dynamically e.g. body.style.fontWeight = 'normal'; etc..

I can't find in any documentation how to manipulate link colours using style attributes. i.e. the JS equivalent of the styles:-

a: link {color: ...;}
a: visited {color: ...;}

Can anyone point me in the right direction please?

Fotiman

2:16 pm on Jun 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rather than modify the style object directly, you might find it easier to simply create CSS classes with the styles you want, and then use JavaScript to swap the classes. Not only is this a cleaner separation of presentation and behavior, it's also better performing than modifying the style object directly (if I recall correctly).

jaytee

3:17 pm on Jun 13, 2007 (gmt 0)

10+ Year Member



Thanks for taking the time to answer.

The application is actually to preview a page design in an iframe from the parent page, so performance is not really an issue as the user's settings will be saved and ultimately go into a 'fixed' style block. The user is able to modify text colours, fonts, backgrounds etc, before putting the page 'live'. I have been able to manipulate in real time over 30 page elements, but it is just the link colours that are proving elusive.