Created
May 4, 2012 06:27
-
-
Save mikechambers/2592601 to your computer and use it in GitHub Desktop.
Example that shows how to dynamically apply and remove style sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.test { | |
color:#FF0000; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>TITLE</title> | |
<link rel="stylesheet" href="default.css"> | |
<script src="jquery.js"></script> | |
<script src="main.js"></script> | |
</head> | |
<body> | |
<div class="test">Hi!</div> | |
<div><a href="#" id="toggle_div">Toggle Style Sheets</a></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$("#toggle_div").click( | |
function(event){ | |
if(document.getElementById("new_css")){ | |
$("#new_css").remove(); | |
} | |
else{ | |
$("head").append("<link id=\"new_css\" />"); | |
$("#new_css").attr({ | |
"rel": "stylesheet", | |
"type": "text/css", | |
"href": "new.css" | |
} | |
); | |
} | |
} | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.test { | |
color:#00FF00; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment