/    Sign up×
Community /Pin to ProfileBookmark

switching style sheets

I’ve read the article at alistapart.com. Ok, but why is it so complex?

The following works in the browsers I have at hand: IE 6, Firefox 1, Netscape 7.1, Opera 7.5 – all browsers for Windows. I don’t have access to a Mac or other machines. BTW, I got this from the “JavaScript & DHTML Cookbook” by Goodman.

It doesn’t do anything in NS4.8 (the only legacy browser I have) but I don’t care what happens in a non-modern browsers. And since my styles are simple and I’m not using positioning, it really doesn’t break the function of the page.

What am I missing here? Is the ala so complex because of extensive cross-browser compatability?

thx

<html>
<head>
<link id=”styles” rel=”stylesheet” type=”text/css”
href=”style1.css” />
<script type=”text/javascript”>
var style = 1;
function changeStyle() {
if (window.document.getElementById) { //modern browser?
if (style == 1) {
window.document.getElementById(“styles”).href =
“style2.css”;
style = 2;
}
else {
window.document.getElementById(“styles”).href =
“style1.css”;
style = 1;
}
} //end if (window.dcoument.getElementById} check
} //end changeStyle()
</script>
</head>
<body>
<p>this will change</p>
<form>
<input type=”button” value=”Click to change style”
onclick=”changeStyle();”/>
</form>
</body>
</html>

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobNov 11.2004 — It's complex because what if users have disabled Javascript? Believe it or not, users find many of Javascripts affects annoying. Thus, they disable it. Using a server side language is much more reliable.
Copy linkTweet thisAlerts:
@CODanauthorNov 12.2004 — Now I know.

Thank you
×

Success!

Help @CODan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...