0

How to convert and display a table data into json object onclick of a button.

I HV a table which has few rows and 3 cols. I want to read the table data on click of a button and save it into Jason format. how can I acheive it. using jQuery or JavaScript.

14th May 2017, 7:21 PM
sawan verma
sawan verma - avatar
1 Resposta
0
var lines = $("table tr"); var json = {}; jQuery.each(lines, function(key){ var l = {}; var cols = $(this).find("td"); jQuery.each(cols, function(key, val){ l[key]=val.innerHTML; }); json[key]=l; }) json = JSON.stringify(json); document.body.append(json);
14th May 2017, 8:20 PM
Yaroslav Pieskov
Yaroslav Pieskov - avatar