Currently, I am in the process of fetching data from an API and displaying it in a tabular format using JavaScript. While I have successfully retrieved the data, I'm facing an issue with applying Bootstrap styling to the table headers.
async function Sports() {
let Api = "https://inshortsapi.vercel.app/news?category=sports";
let result = await (await fetch(Api)).json();
document.write(` <table class='table'>
<thead class='thead-dark'>
<tr><th>SR NO</th>
<th> AUTHOR NAME</th>
<th>CONTENT</th>
<th>DATE </th>
</tr></thead>`);
for (var i = 0; i < result.data.length; i++) {
document.write(`<tbody><tr>
<td>${i+1}</td>
<td>${result.data[i]["author"]}</td>
<td>${result.data[i]["content"]}</td>
<td>${result.data[i]["date"]}</td>
</tr></tbody>`)
}
document.write("</table>")
}
Sports();
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="27454848535453554657671209140914">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea9a859a9a8f98c48099aadbc4dbdec4d9">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="14767b7b60676066756454203a253a27">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
I am envisioning a table design like this []
Regrettably, the outcome I ended up with was not as expected, and the table format looked different from what I had in mind.