Seeking assistance to fix a bug in my JavaScript program. The code works perfectly on Google Chrome and Firefox, however it encounters an error in Internet Explorer 8 as indicated below. Any suggestions on how to resolve this issue would be greatly appreciated. Please find the link to the fiddle below:
Error Message:
SCRIPT438: Object doesn't support property or method 'keys'
File: treelist.js, Line: 12, Column: 13
var dataSource = {
"Watch": {
"Titan": {},
"parent": {
"leaf1": {},
"leaf2": {}
},
}
},
traverseObject = function (obj) {
var ul = document.createElement("ul"),
li;
for (var prop in obj) {
li = document.createElement("li");
li.appendChild(document.createTextNode(prop));
li.onclick = function(e) {
var classNames = e.currentTarget.className;
if (classNames.indexOf("hidden") == -1) {
e.currentTarget.className += "hidden";
} else {
e.currentTarget.className = e.currentTarget.className.replace("hidden", "");
}
e.stopPropagation();
}
if (typeof obj[prop] == "object" && Object.keys(obj[prop]).length) {
li.appendChild(traverseObject(obj[prop]));
} else {
li.className += "leaf";
}
ul.appendChild(li);
console.log(ul);
}
return ul;
};
window.onload = function () {
document.getElementById("dvList1").appendChild(traverseObject(dataSource));
}
Thank you