Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 18th, 2004, 05:57 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changing StyleSheets

Hello Everyone and thanks for your help in advance. I am developing a DHTML page with various rollover effects. I know that styles can be changed for an element via javascript. But I wanted to know if the CSS class for an element could be changed instead of changing each attribute separately, i.e. style.background.color? It would seem that this would be an easier way if possible, to change attributes rather than hardcoding it. Any feedback on this would be greatly appreciated. Thanks.

Reply With Quote
  #2 (permalink)  
Old May 18th, 2004, 07:06 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Hugh,

Long time no see ;)

You can use the className property to change the class info for an entire object. The following example shows hows this works (it's really simple; just set myObject.className = 'NewClassName';):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Change CSS Class</title>
    <style type="text/css">
    .ClassOut
    {
        background-color: black;
        color: white;
        font-weight: bold;
    }
    .ClassOver
    {
        background-color: white;
        color: black;
        font-weight: bold;
        border: 1px solid black;
    }
    </style>
</head>
<body>

<p class="ClassOut" onMouseOver="this.className='ClassOver';" 
        onMouseOut="this.className='ClassOut';">
Hi, I am a paragraph with text. If you hover your mouse 
    over me, my color changes . This is done by setting the 
<a href="http://msdn.microsoft.com/library/default.asp?
    url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp?frame=true">
        className</a> CSS property.
</p>

</body>
</html>
Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old May 18th, 2004, 03:40 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help. Worked like a charm.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing stylesheets in FF & IE6 hericles Javascript How-To 0 August 15th, 2007 05:42 AM
passing parameters to xsl stylesheets smys123 Java Basics 2 June 22nd, 2007 03:42 PM
changing ActiveCell sedolphi Excel VBA 1 May 17th, 2004 02:37 PM
CSS Stylesheets Lucy Dreamweaver (all versions) 4 November 4th, 2003 04:14 PM



All times are GMT -4. The time now is 08:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.