Table 1

In this example below you will see how to do a Table 1 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by christianparker, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright christianparker ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Table 1</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <table cellspacing="0">
  <tr>
    <th>Name</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Tim</td>
    <td class="age">34</td>
  </tr>
  <tr>
    <td>Chloe</td>
    <td class="age">13</td>
  </tr>
  <tr>
    <td>Simon</td>
    <td class="age">22</td>
  </tr>
  <tr>
    <td>Albert</td>
    <td class="age">57</td>
  </tr>

</table>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/christianparker/table-1-OMaZgO */
table {
  width: 300px;
  text-align: center;
  font-family: sans-serif;
}

tr {
  background-color:#dddddd;
}

tr:hover {
  background:#333;
  color:white;
}

tr:nth-of-type(even){
  background-color:#eee;
}

tr.high {
  background-color:red;
}

th, td {
  padding:5px;
}

th {
  font-size: 1.2em;
  background-color: black;
  color: white;
}

/*Downloaded from https://www.codeseek.co/christianparker/table-1-OMaZgO */
// Set Base Value
var base = 23;

// Loop through rows
$('tr').each(
  function() {
    
    // Check cell value against base
    var value = $(this).children('.age').text();
    console.log(value);

    // check If greather than base 
    if (value > base) {
      console.log('true');

      //change background of row
      $(this).addClass('high');

    } else {
      console.log('false')
    }

  }
);

Comments