Skip to content

Instantly share code, notes, and snippets.

@Stevenlitton
Created November 2, 2013 22:45
Show Gist options
  • Save Stevenlitton/7284323 to your computer and use it in GitHub Desktop.
Save Stevenlitton/7284323 to your computer and use it in GitHub Desktop.
Use jQuery to switch stylesheets using button clicks
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="day.css">
<style>
</style>
</head>
<body>
<button data-file="day">Day</button>
<button data-file="night">Night</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var link = $('link');
$('button').click(function(){
var stylesheet = $(this).data('file');
$(this).siblings('button').removeAttr('disabled');
link.attr('href', stylesheet + '.css');
$(this).attr('disabled', 'disabled');
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment