jQuery practice

by marketingaddict8

HTML

<button id="lg-btn">Light Gray Bg</button><button id="dg-btn">Dark Gray Bg</button>
<div id="template">
  <h1>
  Headline
  </h1>
  <p>Paragraph.</p>
</div>

CSS

body {
  background: #fff;
  padding: 20px;
  font-family: Helvetica;
}

#template {
  background: #eee;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;
}

button {
  background: #0084ff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
  margin-right: 10px;
}

.light-gray-bg {
  background: #eee !important;
  color: #333;
  margin-top: 40px;
  width: 200px;
}

.dark-gray-bg {
  background: #333 !important;
  color: #fff;
}

JavaScript

// find elements
const template = $("#template");
const lgButton = $("#lg-btn");
const dgButton = $("#lg-btn");

// handle click and add class
lgButton.on("click", () => {
	template.remo
  template.addClass("light-gray-bg")
});

dgButton.on("click", () => {
  template.addClass("dark-gray-bg")
});