jQuery toggleClass example

Toggle class name on click in jQuery

HTML

<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207394">The Super Mario Bros Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207423">Guardians of the The Galaxy Vol 3 Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207435">Evil Dead Rise Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207441">John Wick Chapter 4 Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207443">Dungeons & Dragons: Honor Among Thieves Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207445">Creed 3 Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207449">Are You There God? It's Me, Margaret. Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207454">Scream 6 Full Movie</a>
<a href="https://www.open.edu/openlearncreate/mod/oublog/view.php?id=207461">Love Again Full Movie</a>

CSS

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

#banner-message {
  background: #fff;
  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;
}

#banner-message.alt {
  background: #0084ff;
  color: #fff;
  margin-top: 40px;
  width: 200px;
}

#banner-message.alt button {
  background: #fff;
  color: #000;
}

JavaScript

// find elements
var banner = $("#banner-message")
var button = $("button")

// handle click and add class
button.on("click", () => {
  banner.toggleClass("alt")
})