Eric Eric - 1 year ago 112
Javascript Question

Javascript Error: Cannot Convert Object to Primitive Value

I'm receiving this error using the following javascript code:

function tempTest(evt) {
ct = document.getElementById(;
rslt = document.getElementById('rslt');
var props;
for (var prop in ct) {
if (ct.hasOwnProperty(prop)) {
propVal = ct[prop];
var propDat = prop + ' = ' + propVal;
props += propDat + '<br/>';
rslt.innerHTML = props;

This one has me puzzled. Any ideas?

Answer Source

Not all the properties of a HTML element are primitives. for example, parent, childs etc are also HTML elements. You can't just use them as strings or numbers.
You need to add there a condition and use that property accordingly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download