Trying to figure out how to apply striping to table rows without directly referencing tag names or class names. The solution should be abstracted within the stripeRows() function in JavaScript, without using jQuery or innerHTML.
I'm almost there but struggling with a certain aspect of the file. Should I loop through the rows in the stripeMeTable() and webcoursesTable() functions or in the stripeRows(tableID,odd,even,over) function?
Below is my HTML and JavaScript code that needs to work seamlessly across both pages:
Sample HTML Code (page 1):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Striped Tables</title>
<link rel="stylesheet" type="text/css" href="striped-tables.css" />
<script type="text/javascript" src="striped-tables.js"></script>
</head>
<body>
<h1>Striped Tables</h1>
<table id="stripeme">
<tr>
<th>Food</th>
<th>Rating</th>
</tr>
<tr class="lines">
<td>Chocolate</td>
<td>delicious</td>
</tr>
// more table rows...
</table>
</body>
</html>
More HTML (page 2):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Is your script abstracted?</title>
<link rel="stylesheet" type="text/css" href="abstraction.css" />
<script type="text/javascript" src="striped-tables.js"></script>
</head>
<body>
<h1>Another Striped Table</h1>
<table id="webcourses">
<tr>
<th>Course number</th>
<th>Course content</th>
</tr>
// more table rows...
</table>
</body>
</html>
JavaScript File:
// JavaScript functions for striped tables
addLoadEvent(stripemeTable);
addLoadEvent(webcoursesTable);
function stripemeTable() {
// Implementation details ...
}
function webcoursesTable() {
// Implementation details ...
}
// End of JavaScript.
The challenge lies in looping through the table rows in a generic, abstracted way inside the stripeRows() function without explicitly referencing tag names:
function stripeRows(tableID, odd, even, over) {
// Implementation details ...
}