Skip to content

Instantly share code, notes, and snippets.

@glenwatson
Created June 18, 2012 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenwatson/2949358 to your computer and use it in GitHub Desktop.
Save glenwatson/2949358 to your computer and use it in GitHub Desktop.
table to unordered list
<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