I need some help with my JavaScript, i am trying to sorting XML data with the help of JavaScript, and i am successful doing the sorting part, but the output is returning [object Object], which i don't want it to be printed out, so i need some help to get this thing fixed so that i get a proper output. I am attaching a live fiddle. All these needs to be done with JavaScript and not JQUERY.
I don't want [object Object],[object Object] to be printed as output. I want the output as following format.
Live Fiddle
bookstore
|
|__book
| |_____title
| |_____author
| |_____year
| |_____price
|
|__book
|
|__book
|
|__book
function generate(obj){
// alert((obj[prop])+": "+typeof(obj));
var ul = document.createElement("ul"),
li,span;
for (var prop in obj){
li = document.createElement("li");
li.appendChild(document.createTextNode(obj[prop]));
li.onclick = function(e) {
e = e || window.event;
if ((e.target || e.srcElement).tagName !== "LI") return;
var classNames = this.className;
if (classNames.indexOf("hidden") == -1) {
this.className += "hidden";
} else {
this.className = this.className.replace("hidden", "");
}
if (!e)
e = window.event;
if (e.stopPropagation) {
e.stopPropagation();
}
else {
e.cancelBubble = true;
}
}
if (typeof obj[prop] == "object" && Objectkeys(obj[prop]).length) {
li.appendChild(generate(obj[prop]));
} else {
li.className += "leaf";
}
ul.appendChild(li);
console.log(ul);
}
return ul;
}
Thank you