469,312 Members | 2,493 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

swop between css files?

Hello

Is it possible to use javascript to swop between css files?

Cheers

Geoff
Jul 20 '05 #1
5 1178
Geoff Cox wrote:
Hello

Is it possible to use javascript to swop between css files?

Cheers

Geoff


Only in latest browsers. I was able to get it working in Gecko and IE6.0

For an example of client-side stylesheet switcher, see my customization
gadget at http://www.klproductions.com

Vladdy.

Jul 20 '05 #2
In article <m9********************************@4ax.com>, Geoff Cox
<ge*******@dontspamblueyonder.co.uk> writes:
Is it possible to use javascript to swop between css files?


<link rel="stylesheet" type="text/css" href="testFile1.css" id="linkTag">

Add an id attribute to your link tag and then change its .href property..

function changeCSSFile(newFile){
document.getElementById('linkTag').href = newFile;
}

Works in IE6.0, Firebird 1.4 and Opera 7.

Test page at <URL:
http://members.aol.com/_ht_a/hikksno...ile/index.html />
--
Randy
Jul 20 '05 #3
I found that by referencing the style sheet via a <link tag:
<link id="css_ref" type="text/css" href="stylesheet1.css" />

you can change its file reference using:
document.getElementById('css_ref').href="new_style sheet.css"

This seems to work in MSIE 6 and NN7;

If you don't want to change an entire stylesheet, just the class, you can give
your element an id and change the class thusly:
<div id="redtext"
onMouseover="document.getElementById(this.id).clas sName='newclassname' " >

The class name changer appears to work for MSIE6 and NN7.

Hope this helps,

Jim
Jul 20 '05 #4
In article <20***************************@mb-m03.aol.com>,
ji*******@aol.comNoSpam (JimMenees) writes:
If you don't want to change an entire stylesheet, just the class, you can
give
your element an id and change the class thusly:
<div id="redtext"
onMouseover="document.getElementById(this.id).cla ssName='newclassname' " >

The class name changer appears to work for MSIE6 and NN7.


That can be simplified to:

<div id="redtext" onMouseover="this.className='newclassname' " >

--
Randy
Jul 20 '05 #5
On 25 Dec 2003 00:24:48 GMT, hi************@aol.com (HikksNotAtHome)
wrote:
In article <20***************************@mb-m03.aol.com>,
ji*******@aol.comNoSpam (JimMenees) writes:
If you don't want to change an entire stylesheet, just the class, you can
give
your element an id and change the class thusly:
<div id="redtext"
onMouseover="document.getElementById(this.id).cl assName='newclassname' " >

The class name changer appears to work for MSIE6 and NN7.


That can be simplified to:

<div id="redtext" onMouseover="this.className='newclassname' " >


Thanks everyone - will have a try!

Cheers

Geoff

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by JKop | last post: by
3 posts views Thread by pooja | last post: by
11 posts views Thread by ambika | last post: by
22 posts views Thread by Daniel Billingsley | last post: by
18 posts views Thread by UJ | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.