HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<table class="functionableTable" id="covid19TableWithSort">
<thead>
<tr class="titleRow">
<th id="tableTitle">CANADIAN COVID CASES (Reported on April 23, 2021)</th>
</tr>
<tr class="headings">
<th class="colHeader">Province <button class="sort" id="provSort" onclick="sortTableByColNum('1')"><i class="down-arrow" id="provSortIcon">▼</i></button> <p id="provSortValue" hidden>0</p></th>
<th class="colHeader">Population <button class="sort" id="popSort" onclick="sortTableByColNum('2')"><i class="down-arrow" id="popSortIcon">▼</i></button><p id="popSortValue" hidden>0</p></th>
<th class="colHeader">Cases <button class="sort" id="casesSort" onclick="sortTableByColNum('3')"><i class="down-arrow" id="casesSortIcon">▼</i></button><p id="casesSortValue" hidden>0</p></th>
<th class="colHeader">Recoveries <button class="sort" id="recoveriesSort" onclick="sortTableByColNum('4')"><i class="down-arrow" id="recoveriesSortIcon">▼</i></button><p id="recoveriesSortValue" hidden>0</p></th>
<th class="colHeader">Deaths <button class="sort" id="deathsSort" onclick="sortTableByColNum('5')"><i class="down-arrow" id="deathsSortIcon">▼</i></button><p id="deathsSortValue" hidden>0</p></th>
<th class="colHeader">Active <button class="sort" id="activeSort" onclick="sortTableByColNum('6')"><i class="down-arrow" id="activeSortIcon">▼</i></button><p id="activeSortValue" hidden>0</p></th>
</tr>
</thead>
<tbody>
<tr>
<td>British Columbia</td>
<td>5,145,851</td>
<td>122,757</td>
<td>112,235</td>
<td>1,550</td>
<td>8,733</td>
</tr>
<tr>
<td>Alberta</td>
<td>4,428,112</td>
<td>177,087</td>
<td>155,851</td>
<td>2,054</td>
<td>19,182</td>
</tr>
<tr>
<td>Saskatchewan</td>
<td>1,177,884</td>
<td>39,137</td>
<td>36,162</td>
<td>470</td>
<td>2,505</td>
</tr>
<tr>
<td>Manitoba</td>
<td>1,379,584</td>
<td>37,069</td>
<td>34,366</td>
<td>967</td>
<td>1,739</td>
</tr>
<tr>
<td>Ontario</td>
<td>14,733,119</td>
<td>437,310</td>
<td>387,712</td>
<td>7,863</td>
<td>41,735</td>
</tr>
<tr>
<td>New Brunswick</td>
<td>781,315</td>
<td>1,823</td>
<td>1,642</td>
<td>34</td>
<td>146</td>
</tr>
<tr>
<td>Prince Edward Island</td>
<td>159,713</td>
<td>175</td>
<td>164</td>
<td>0</td>
<td>11</td>
</tr>
<tr>
<td>Nova Scotia</td>
<td>979,115</td>
<td>1,938</td>
<td>1,721</td>
<td>67</td>
<td>150</td>
</tr>
<tr>
<td>Newfoundland & Labrador</td>
<td>520,998</td>
<td>1,053</td>
<td>1,020</td>
<td>6</td>
<td>23</td>
</tr>
<tr>
<td>Yukon</td>
<td>42,176</td>
<td>80</td>
<td>75</td>
<td>1</td>
<td>4</td>
</tr>
<tr>
<td>Northwest Territories</td>
<td>45,074</td>
<td>46</td>
<td>43</td>
<td>0</td>
<td>3</td>
</tr>
<tr>
<td>Nunavut</td>
<td>39,285</td>
<td>441</td>
<td>400</td>
<td>4</td>
<td>37</td>
</tr>
</tbody>
</table>
<div class="sectionFooter">
<p id="reference">Data obtained from Wikipedia: <a href="https://en.wikipedia.org/wiki/Template:COVID-19_pandemic_data/Canada_medical_cases_by_province">COVID-19 Data</a> </p>
</div>
table{
line-height: 35px;
border: 2px solid black;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
margin: 0 auto;
}
tbody{
font-family: "Helvetica-Neue", Helvetica, Arial;
font-size: 1.1em;
}
tbody tr:nth-child(odd){
background-color: #ebedee;
color: #000000;
}
tbody tr:nth-child(even){
background-color: #d3d2d2;
color: #000000;
}
tbody tr td:first-child{
text-align: left;
padding-left: 10px;
}
tbody tr{
opacity: 0.8;
}
tbody tr:hover{
font-weight: bold;
/*text-shadow: 1px 1px #cac9c9;*/
opacity: 1;
}
tbody tr td:nth-child(2), tbody tr td:nth-child(3), tbody tr td:nth-child(4), tbody tr td:nth-child(5), tbody tr td:nth-child(6){
text-align: center;
}
.sectionFooter p{
font-family: Helvetica, Arial, sans-serif;
font-size: 1em;
text-align: center;
}
.headings{
background-image: linear-gradient(180deg, #526bfa, #0522c5);
color: #ffffff;
font-family: "Helvertica Neue", Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 1.2em;
margin: 2% 0 3% 0;
}
.headings th:nth-child(1){
text-align: left;
padding: 2px 0 2px 10px;
}
.tr {
margin-left: 5%;
margin-right: 5%;
}
.headings button{
margin-bottom: 10px;
}
#tableTitle{
font-size: 1.3em;
padding: 5px 0 5px 10px;
}
var colSortValue;
var colToSkip;
var tableDataArray;
var table, rows, continueSort, switchRow, curRow, nextRow, dirToSort, counter;
var numberOrString;
function resetIcons(){
// Changes the icons back to default (chevron down icon
var test;
var element;
var iconsToChange = $("i");
console.log("coltoskip: " + colToSkip)
for(i = 0; i < iconsToChange.length; i++){
test = iconsToChange[i].id;
if(test != colToSkip)
{
$("#" + test).removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
}
}
function getValues(){
// Gets the table values
table = document.getElementById("covid19TableWithSort");
rows = table.rows;
}
function sortTableByColNum(intColNum){
/* Changes the curremt icon on the row header for the selected row to sort and changes the icons for the othe columms back to default
Sets the current search value for the search direction - 0 = down, 1 = up
Starts the search procedure */
var element;
switch(parseInt(intColNum)){
case 1:
colToSkip = "provSortIcon";
element = $("#provSortValue");
colSortValue = element.html();
if(colSortValue == 0){
$("#provSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");
}
if(colSortValue == 1){
$("#provSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
break;
case 2:
colToSkip = "popSortIcon";
element = $("#popSortValue");
colSortValue = element.html();
if(colSortValue == 0){
$("#popSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");
}
if(colSortValue == 1){
$("#popSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
break;
case 3:
colToSkip = "casesSortIcon";
element = $("#casesSortValue");
colSortValue = element.html();
if(colSortValue == 0){
$("#casesSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");
}
if(colSortValue == 1){
$("#casesSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
break;
case 4:
colToSkip = "recoveriesSortIcon";
element = $("#recoveriesSortValue");
colSortValue = element.html();
if(colSortValue == 0){
$("#recoveriesSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");
}
if(colSortValue == 1){
$("#recoveriesSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
break;
case 5:
colToSkip = "deathsSortIcon";
element = $("#deathsSortValue");
colSortValue = element.html();
if(colSortValue == 0){
$("#deathsSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");
}
if(colSortValue == 1){
$("#deathsSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
break;
case 6:
colToSkip = "activeSortIcon";
element = $("#activeSortValue");
colSortValue = element.html();
if(colSortValue == 0){
$("#activeSortIcon").removeClass("fa-chevron-down").addClass("fa-chevron-up");
}
if(colSortValue == 1){
$("#activeSortIcon").removeClass("fa-chevron-up").addClass("fa-chevron-down");
}
break;
}
if(colSortValue == 0){
dirToSort = "down";
element.html(1);
}
if(colSortValue == 1){
dirToSort = "up";
element.html(0);
}
resetIcons();
sortTable(intColNum);
/*$(this).find($(".fa")).removeClass('fa-chevron-down').addClass('fa-chevron-up');*/
}
function sortTable(colNum){
var numberOfPasses;
var columnToSortBy = colNum - 1;
var value1, value2;
getValues();
continueSort = true;
counter = rows.length;
while(continueSort){
for(numberOfPasses = 0; numberOfPasses < counter; numberOfPasses++){
for(i = 2; i < rows.length - 1; i++){
if(colNum > 1){
numToCompare1 = rows[i].getElementsByTagName("td")[columnToSortBy];
curRow = parseInt(numToCompare1.innerHTML.replace(/,/g, ''));
numToCompare2 = rows[i + 1].getElementsByTagName("td")[columnToSortBy];
nextRow = parseInt(numToCompare2.innerHTML.replace(/,/g, ''));
value1 = curRow;
value2 = nextRow;
}
else{
curRow = rows[i].getElementsByTagName("td")[columnToSortBy];
nextRow = rows[i + 1].getElementsByTagName("td")[columnToSortBy];
value1 = curRow.innerHTML.toUpperCase();
value2 = nextRow.innerHTML.toUpperCase();
}
console.log("Value 1: " + value1 + " Value 2: " + value2);
if(dirToSort == "down"){
if(value1 > value2 ){
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
continueSort = true;
}
else{
continueSort = false;
}
}
if(dirToSort == "up"){
if(value1 < value2){
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
continueSort = true;
}
else{
continueSort = false;
}
}
}
}
}
}
Also see: Tab Triggers