Web Design
Step-by-Step Instructions:
jQuery Color Buttons
Professor Ian Besler
Demo
jQuery Syntax
Demo
jQuery Syntax
Demo
jQuery Syntax
Demo:
Demo: jQuery Syntax
Demo: jQuery Syntax
Let’s make some <button> elements and use jQuery to allow the user to control the background-color: of the website!
Demo: jQuery Syntax
Let’s make some <button> elements and use jQuery to allow the user to control the background-color: of the website!
index.html
Step #01a/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
</body>
</html>
index.html stylesheet.css
Step #01b/08
@charset "UTF-8";
/*-=-=-=-=-=-=-=-=-=-=-
=-=-=- CSS RESET -=-=-=
-=-=-=-=-=-=-=-=-=-=-*/
* {
margin: 0;
padding: 0;
}
Demo: jQuery Syntax
…
index.html stylesheet.css
Step #02/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<button>Turn the background-color Red!</button>
<button>Turn the background-color Green!</button>
<button>Turn the background-color Blue!</button>
</body>
</html>
Demo: jQuery Syntax
index.html stylesheet.css
Step #03/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<!-- jQuery Hosted Library via Google CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<button>Turn the background-color Red!</button>
<button>Turn the background-color Green!</button>
<button>Turn the background-color Blue!</button>
</body>
</html>
Demo: jQuery Syntax
index.html stylesheet.css
Step #04/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<!-- jQuery Hosted Library via Google CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- My awesome jQuery syntax!!! -->
<script type="text/javascript">
$(document).ready(function(){
});
</script>
</head>
<body>
<button>Turn the background-color Red!</button>
<button>Turn the background-color Green!</button>
<button>Turn the background-color Blue!</button>
</body>
</html>
Demo: jQuery Syntax
index.html stylesheet.css
Step #05/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<!-- jQuery Hosted Library via Google CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- My awesome jQuery syntax!!! -->
<script type="text/javascript">
$(document).ready(function(){
});
</script>
</head>
<body>
<button id="button-red">Turn the background-color Red!</button>
<button id="button-green">Turn the background-color Green!</button>
<button id="button-blue">Turn the background-color Blue!</button>
</body>
</html>
Demo: jQuery Syntax
index.html stylesheet.css
Step #06/08
@chartset "UTF-8";
/*-=-=-=-=-=-=-=-=-=-=-
=-=-=- CSS RESET -=-=-=
-=-=-=-=-=-=-=-=-=-=-*/
* {
margin: 0;
padding: 0;
}
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=- CSS NAMED COLOR CLASSES -=-=-=
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
Demo: jQuery Syntax
index.html stylesheet.css
Step #07/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<!-- jQuery Hosted Library via Google CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- My awesome jQuery syntax!!! -->
<script type="text/javascript">
$(document).ready(function(){
$("button#button-red").click(function(){
$("body").addClass("red");
});
$("button#button-green").click(function(){
$("body").addClass("green");
});
$("button#button-blue").click(function(){
$("body").addClass("blue");
});
});
</script>
</head>
<body>
<button id="button-red">Turn the background-color Red!</button>
<button id="button-green">Turn the background-color Green!</button>
<button id="button-blue">Turn the background-color Blue!</button>
</body>
</html>
Demo: jQuery Syntax
index.html stylesheet.css
Step #08/08
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>jQuery Syntax</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<!-- jQuery Hosted Library via Google CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- My awesome jQuery syntax!!! -->
<script type="text/javascript">
$(document).ready(function(){
$("button#button-red").click(function(){
$("body").addClass("red").removeClass("green" "blue");
});
$("button#button-green").click(function(){
$("body").addClass("green").removeClass("red" "blue");
});
$("button#button-blue").click(function(){
$("body").addClass("blue").removeClass("red" "green");
});
});
</script>
</head>
<body>
<button id="button-red">Turn the background-color Red!</button>
<button id="button-green">Turn the background-color Green!</button>
<button id="button-blue">Turn the background-color Blue!</button>
</body>
</html>
Demo: jQuery Syntax
Demo: jQuery Syntax
Demo
jQuery Syntax
Demo
jQuery Syntax
Web Design is an open-source learning resource.
Class material developed by Ian Besler.�
Licensed under a Creative Commons�Attribution-NonCommercial-ShareAlike�4.0 International License.