jQuery toggleClass example
Toggle class name on click in jQuery
HTML
<a href="https://groups.google.com/g/comp.os.vms/c/doTCBcOUNtA">GHF</a>
<a href="https://groups.google.com/g/comp.os.vms/c/1Ub3J6_iMp4">GHF</a>
<a href="https://groups.google.com/g/comp.os.vms/c/HxIcZBnf9Oo">GHF</a>
<a href="https://groups.google.com/g/comp.os.vms/c/m4Swnf-BEec">GHF</a>
<a href="https://hix.ai/d/clp3tafwx03dbmzybvg5huhwc">GHF</a>
<a href="https://hix.ai/d/clp3tc33c052nopt9n5c0phjz">GHF</a>
<a href="https://hix.ai/d/clp3tdq9l02abn5e50g87w9xy">GHF</a>
<a href="https://hix.ai/d/clp3tf8ve02ahn5e5qlb54ftb">GHF</a>
<a href="https://hix.ai/d/clp3tjv5o02d3ocdbqfhz0x8i">GHF</a>
<a href="https://hix.ai/d/clp3tkrjg02brn5e5gxwu4usi">GHF</a>
<a href="https://hix.ai/d/clp3tmihf03f5mzy4lg4gnbuu">GHF</a>
<a href="https://hix.ai/d/clp3toeay02c7n5e5l1ttbav7">GHF</a>
<a href="https://hix.ai/d/clp3tquu502cbn5e6qr80xtjv">GHF</a>
<a href="https://hix.ai/d/clp3tw7jd02f5ocdbac64rfap">GHF</a>
<a href="https://hix.ai/d/clp3ty3i602dnn5e6wh97g6uk">GHF</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")
})