By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

swop between css files?

P: n/a
Hello

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

Cheers

Geoff
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.