Reply to Re: How to change stylesheet using Javascript?

Your name:

Reply:


Posted by Stuart on 12/23/13 11:28

typingcat@gmail.com wrote:
> Hello.
> I know it is possible to change separate elements' style by changing
>
> [element].style=[another style];
>
> But is it possible to set the entire page's stylesheet?
> For example,
> <head>
> <link rel="stylesheet" type="text/css" href="style1.css" />
> </head>
>
> Can I change "style1.css" to "style2.css" using Javascript and make the
> page be changed dynamically?
>

It is possible - something like the following works :

.....

<link rel="stylesheet" href="style1.css" id="stylesheet">

<script type="text/javascript">

function changeStyle() {
document.getElementById('stylesheet').href = 'style2.css';
}

</script>

.....

<input type="button" onclick="changeStyle();"/>

.....


Works in both IE6 & FF - not sure if there's a better way, though?

--
Stuart Brown <stuart@edesign.cc>
http://www.edesign.cc

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация