jQuery addClass example
Change class name on click in jQuery
by bigwelly
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/7.1.0/highcharts.js"></script>
<div class="container">
<table id="dt-table">
<thead>
<tr>
<th>Country</th>
<th>Population (2017)</th>
<th>Density (P/Km²)</th>
<th>Med. Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>China</td>
<td>1,409,517,397</td>
<td>150</td>
<td>37</td>
</tr>
<!-- 24 more rows here -->
</tbody
</table>
<div id="chart"></div>
</div>
CSS
.container {
display: flex;
flex-wrap: wrap;
align-items: center;
padding: 0 10px;
}
#dt-table_wrapper {
width: 35%;
margin-right: 2%;
}
#chart {
width: 63%;
}
table {
text-align: left;
}
@media screen and (max-width: 1200px) {
#dt-table_wrapper,
#chart {
width: 100%;
}
#dt-table_wrapper {
margin-right: 0;
}
}
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
function init() {
const table = $("#dt-table").DataTable();
const tableData = getTableData(table);
createHighcharts(tableData);
setTableEvents(table);
}