Created
June 18, 2012 16:49
-
-
Save glenwatson/2949358 to your computer and use it in GitHub Desktop.
table to unordered list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script> | |
<script type="text/javascript"> | |
$(document).ready(function() | |
{ | |
var unorderedGradesList = $('<ul></ul>') //Create the unordered list to put the grades into | |
.addClass("grades"); | |
$('tr > td').each(function(index, element) //Get the table's contents and loop over them | |
{ | |
unorderedGradesList.append('<li>'+$(element).text().trim()+'</li>'); //Get whatever was in the table's data element, create a list item for it, and append it to the unorderedGradesList | |
}) | |
.hide(); //You can of course delete the table outright when you are done with it. | |
unorderedGradesList.appendTo('body'); //append the list wherever you want | |
}); | |
</script> | |
</head> | |
<body> | |
<table> | |
<tr> | |
<td>11</td> | |
<td>12</td> | |
<td>13</td> | |
</tr> | |
<tr> | |
<td>21</td> | |
<td>22</td> | |
<td>23</td> | |
</tr> | |
<tr> | |
<td>31</td> | |
<td>32</td> | |
<td>33</td> | |
</tr> | |
<tr> | |
<td>41</td> | |
<td>42</td> | |
<td>43</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment