Skip to content

Instantly share code, notes, and snippets.

@sters
Forked from suneo3476/style_change.html
Last active December 18, 2015 14:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sters/5797943 to your computer and use it in GitHub Desktop.
Save sters/5797943 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>スタイルシートそのものを変更する</title>
<link rel="stylesheet" type="text/css" href="style-a.css" id="style-a" disabled="true">
<link rel="stylesheet" type="text/css" href="style-b.css" id="style-b" disabled="true">
<style id="style-c">
#foo {
background-color: #999;
}
</style>
<script>
function change(id, enable){
//チェックボックスでチェックをいれたスタイルを有効にする
document.getElementById(id).disabled = !enable;
}
window.addEventListener('load', function () {
//初期化処理としてすべてのスタイルを無効にする
var styles = document.styleSheets;
for (var i = 0; i < styles.length; i++) {
styles[i].disabled = true;
}
}, false);
</script>
</head>
<body>
<div id="foo">This is sample.</div>
<input type="checkbox" onchange="change('style-a', this.checked)">
<input type="checkbox" onchange="change('style-b', this.checked)">
<input type="checkbox" onchange="change('style-c', this.checked)">
</body>
</html>
<!--
/* style-a.cssの中身 */
#foo {
font-size: x-large;
}
/* style-b.cssの中身 */
#foo {
text-decoration: underline;
}
-->
@suneo3476
Copy link

bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment