I'm currently working on several Apps that include AJAX calls and I'm using JSON format to retrieve data from the server. Each page needs to create content based on the JSON response, and I'm currently creating the content like:
function createBox1(json) {
var bigbox = document.createElement('div');
bigbox.className = 'class1';
var firstbox = document.createElement('div');
firstbox.className = 'first-box';
var firstNestedBox = document.createElement('div');
var secondNestedBox = document.createElement('div');
var thirdNestedBox = document.createElement('div');
var secondbox = document.createElement('div');
...
So basically its kinda a long code and I wanted to know if there is a better way to do it.
PS: I have seen some libraries where they do something like:
function o(t,e){var i=document.createElement(t||"div"),o;for(o in e)i[o]=e[o];return i}
and I suppose that's how they create multiple div elements, but I'm not sure how does that works.
Thanks in Advance (: