Eric Eric - 2 months ago 32
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?


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.