jQuery toggleClass example

Toggle class name on click in jQuery

HTML

<a href="https://www.datacamp.com/portfolio/ufc295live">ONTV</a>
<a href="https://gamma.app/public/UFC-295-LIVE-Free-Broadcast-ON-Tv-Channel-q1dj95mlncmmcgm">ONTV</a>
<a href="https://gamma.app/docs/UFC-295-LIVE-Free-Broadcast-ON-Tv-Channel-q1dj95mlncmmcgm?mode=doc">ONTV</a>
<a href="https://soundcloud.com/stephany-abang/official-ufc-295-live-free-broadcast-on-tv-channel">ONTV</a>
<a href="https://soundcloud.com/stephany-abang/officialppv-erceg-vs-costa-live-broadcast-ufc-295-free-on-11-nov-2023">ONTV</a>
<a href="https://gamma.app/docs/OFFICIALPPV-UFC-295-Live-Broadcast-Free-ON-11-Nov-2023-d6jez670hv3fasb?mode=doc">ONTV</a>
<a href="https://soundcloud.com/stephany-abang/ufc-295-watch-live-free-on-tv-coverage-november-11">ONTV</a>
<a href="https://gamma.app/docs/Heres-How-To-Watch-UFC-295-Live-Streams-FreeReddiT-a9ll25em01gawwe?mode=doc">ONTV</a>
<a href="https://soundcloud.com/stephany-abang/ufc-295-watch-live-free-on-tv-coverage-november-11">ONTV</a>
<a href="https://www.loudounnow.com/getoutloudoun/calendar/?_evDiscoveryPath=%2Fevent%2F2067158">ONTV</a>
<a href="https://www.loudounnow.com/getoutloudoun/calendar/?_evDiscoveryPath=%2Fevent%2F2066759">ONTV</a>
<a href="https://dailyinterlake.com/events/?_evDiscoveryPath=%2Fevent%2F2066759">ONTV</a>
<a href="https://dailyinterlake.com/events/?_evDiscoveryPath=%2Fevent%2F2067158">ONTV</a>
<a href="https://groups.google.com/g/comp.text.tex/c/Z1u0v_jf9Sw">ONTV</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")
})