Created
December 27, 2012 15:38
-
-
Save ccheney/4389114 to your computer and use it in GitHub Desktop.
jQuery: Convert HTML Table to JSON
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
(function($){ | |
var convertTableToJson = function() | |
{ | |
var rows = []; | |
$('table tr').each(function(i, n){ | |
var $row = $(n); | |
rows.push({ | |
display_name: $row.find('td:eq(0)').text(), | |
first_name: $row.find('td:eq(1)').text(), | |
last_name: $row.find('td:eq(2)').text(), | |
street: $row.find('td:eq(3)').text(), | |
city: $row.find('td:eq(4)').text(), | |
state: $row.find('td:eq(5)').text(), | |
zip: $row.find('td:eq(6)').text() | |
}); | |
}); | |
return JSON.stringify(rows); | |
}; | |
$(function(){ | |
console.log(convertTableToJson ()); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment