jQuery addClass example

Change class name on click in jQuery

by Dmitri Ganenco

HTML

<div id="banner-message">
  <p>Hello World</p>
  <button>Change color</button>
</div>

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

const btna = [
{
  "id":"#btn123",
  "formId" : "#wpcf7-f4849-p4850-o1",
  'openTime' : "June 24, 2019 14:00:00",
  'closeTime' : "June 23, 2019 14:00:00",
},
{
  "id":"#btn1234",
  "formId" : "#wpcf7-f4940-p4850-o2",
  'openTime' : "June 23, 2019 14:00:00",
  'closeTime' : "June 25, 2019 14:00:00",
},
{
  "id":"#btn12345",
  "formId" : "#wpcf7-f4941-p4850-o3",
  'openTime' : "June 23, 2019 14:00:00",
  'closeTime' : "June 28, 2019 14:00:00",
}
];


const arr = btna.map(el => {
	el.openTime = addDays(7, el.openTime);
	el.closeTime = addDays(7, el.closeTime);
	
	return el;
});

function addDays(days, dateString) {
	let date = new Date(dateString);
	date.setDate(date.getDate() + days);
	return date;
}

console.log(arr);