SunQuest
           CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 10th, 2003, 11:10 AM
couloir007 couloir007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New Hampshire
Posts: 116 couloir007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 31 m 34 sec
Reputation Power: 6
Post External JS & CSS

Moifying css styles in html file with js is easy enough, but what external css with external js? I can't figure out how to reference the external style sheet with my js. Any one have an example piece of code? Thanks.

Sean

Reply With Quote
  #2  
Old September 10th, 2003, 04:44 PM
jerom jerom is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Posts: 1,014 jerom User rank is Corporal (100 - 500 Reputation Level)jerom User rank is Corporal (100 - 500 Reputation Level)jerom User rank is Corporal (100 - 500 Reputation Level)jerom User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 17 h 34 m 25 sec
Reputation Power: 9
Basically, it does not make a difference whether you're dealing with an external stylesheet or inside the document.
Suppose, you have a stylesheet 'mystyle.css':
Code:
.myclass {
	font-family: verdana, sans-serif;
	font-size: 2em;
	background-color: red;
}

You could manipulate it by using the following JavaScript code:
Code:
<script type="text/javascript">
function changecss(myclass,element,value) {
	var CSSRules
	if (document.all) {
		CSSRules = 'rules'
	}
	else if (document.getElementById) {
		CSSRules = 'cssRules'
	}
	for (var i = 0; i < document.styleSheets.length; i++) {
		for (var j = 0; j < document.styleSheets[i][CSSRules].length; j++) {
			if (document.styleSheets[i][CSSRules][j].selectorText == myclass) {
				document.styleSheets[i][CSSRules][j].style[element] = value
			}
		}	
	}
}

and call this function with:
Code:
<div onclick="changecss('.myclass','backgroundColor','blue')">changecss</div>
<div class="myclass">
myclass content
</div>


Hope this helps,
Jeroen

Reply With Quote
  #3  
Old September 10th, 2003, 09:17 PM
terminal's Avatar
terminal terminal is offline
nx
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: USA
Posts: 626 terminal Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 5 h 28 m 37 sec
Reputation Power: 0
Send a message via AIM to terminal
i believe what would be even ezr would be to do this:
Code:
function changeCSS(cssFile)
{
cssLink.href=cssFile;
}

and then give your <link> tag an id of cssLink and when you call it, call it like so:
onCLick="changeCSS('path_to_your_css_file.css')"
http://terminal.ledohost.com/layout1.html is an example of mine

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > External JS & CSS


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway