jQuery addClass example
Change class name on click in jQuery
HTML
<div id="myElement">
<a href="https://myawesomenewsite.com/departuretime/1253">1253</a>
<a href="https://myawesomenewsite.com/departuretime/1255">1255</a>
<a href="https://myawesomenewsite.com/departuretime/0955">0955</a>
<a href="https://myawesomenewsite.com/departuretime/2213">2213</a>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
.you_have_time{
color:green;
}
.you_dont_have_time{
color:red;
}
#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 rootElements = $("#myElement a");
rootElements.each(function(index, item){
var url = item.href,
arr_split = url.split("/"),
arr_index = arr_split.length-1,
departureTime = arr_split[arr_index],
date = new Date(),
myTime = date.getHours()+''+date.getMinutes();
//add your class like this
item.classList.add(myTime);
//but you can also spice it up a bit
if(departureTime>myTime){
item.classList.add("you_have_time");
}else{
item.classList.add("you_dont_have_time");
}
});