Skip to content

Instantly share code, notes, and snippets.

@parsibox
Created May 27, 2019 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsibox/a0ee2cc5411b246fc882953c51543680 to your computer and use it in GitHub Desktop.
Save parsibox/a0ee2cc5411b246fc882953c51543680 to your computer and use it in GitHub Desktop.
change css variables with jquery!
<!DOCTYPE html>
<html>
<head>
<style>
body {
--color: blue;
background-color: var(--color);
}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
click me!
<script type="text/javascript">
$("html").on('click', function() {
$("body").get(0).style.setProperty("--color", "hotpink");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment