How to convert selected HTML to Json?
What you want to do is called serializing.
// This gives you an HTMLElement object
var element = document.getElementById('TextBoxesGroup');
// This gives you a string representing that element and its content
var html = element.outerHTML;
// This gives you a JSON object that you can send with jQuery.ajax's `data`
// option, you can rename the property to whatever you want.
var data = { html: html };
// This gives you a string in JSON syntax of the object above that you can
// send with XMLHttpRequest.
var json = JSON.stringify(data);
function htmlToJson(div,obj){
if(!obj){obj=[]}
var tag = {}
tag['tagName']=div.tagName
tag['children'] = []
for(var i = 0; i< div.children.length;i++){
tag['children'].push(htmlToJson(div.children[i]))
}
for(var i = 0; i< div.attributes.length;i++){
var attr= div.attributes[i]
tag['@'+attr.name] = attr.value
}
return tag
}
var html = $('#TextBoxesGroup')[0].outerHTML;
var temp = {"html":html};
var obj = JSON.parse(temp);
console.log(obj); // shows json object
You can use any server side language to make a json from obj.